blob: 86127c40542221add81e31f1a7882bf9e756a3b2 [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>
21
22#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070023#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080024#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070026#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070030#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <cutils/jstring.h>
32
33#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070034#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
68
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Constants for response types */
84#define RESPONSE_SOLICITED 0
85#define RESPONSE_UNSOLICITED 1
86
87/* Negative values for private RIL errno's */
88#define RIL_ERRNO_INVALID_RESPONSE -1
89
90// request, response, and unsolicited msg print macro
91#define PRINTBUF_SIZE 8096
92
93// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
108 #define appendPrintBuf(x...) sprintf(printBuf, x)
109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700136 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700141 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142} RequestInfo;
143
Wink Saville3d54e742009-05-18 18:00:44 -0700144typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Etan Cohend3652192014-06-20 08:28:44 -0700151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
185static struct ril_event s_commands_event;
186static struct ril_event s_wakeupfd_event;
187static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700188static SocketListenParam s_ril_param_socket;
189
190static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests = NULL;
193
194#if (SIM_COUNT >= 2)
195static struct ril_event s_commands_event_socket2;
196static struct ril_event s_listen_event_socket2;
197static SocketListenParam s_ril_param_socket2;
198
199static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
200static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
201static RequestInfo *s_pendingRequests_socket2 = NULL;
202#endif
203
204#if (SIM_COUNT >= 3)
205static struct ril_event s_commands_event_socket3;
206static struct ril_event s_listen_event_socket3;
207static SocketListenParam s_ril_param_socket3;
208
209static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
210static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
211static RequestInfo *s_pendingRequests_socket3 = NULL;
212#endif
213
214#if (SIM_COUNT >= 4)
215static struct ril_event s_commands_event_socket4;
216static struct ril_event s_listen_event_socket4;
217static SocketListenParam s_ril_param_socket4;
218
219static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
220static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
221static RequestInfo *s_pendingRequests_socket4 = NULL;
222#endif
223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static struct ril_event s_wake_timeout_event;
225static struct ril_event s_debug_event;
226
227
228static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
229
Etan Cohend3652192014-06-20 08:28:44 -0700230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233
234static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
236
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800237static RequestInfo *s_toDispatchHead = NULL;
238static RequestInfo *s_toDispatchTail = NULL;
239
240static UserCallbackInfo *s_last_wake_timeout_info = NULL;
241
242static void *s_lastNITZTimeData = NULL;
243static size_t s_lastNITZTimeDataSize;
244
245#if RILC_LOG
246 static char printBuf[PRINTBUF_SIZE];
247#endif
248
249/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700250static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800251
252static void dispatchVoid (Parcel& p, RequestInfo *pRI);
253static void dispatchString (Parcel& p, RequestInfo *pRI);
254static void dispatchStrings (Parcel& p, RequestInfo *pRI);
255static void dispatchInts (Parcel& p, RequestInfo *pRI);
256static void dispatchDial (Parcel& p, RequestInfo *pRI);
257static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800258static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
260static void dispatchRaw(Parcel& p, RequestInfo *pRI);
261static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700262static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800263static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700264static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800265static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800266
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700268static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
269static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
270static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700272static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700273static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
274static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800275static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
276static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700277static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700278static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000279static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800280static int responseInts(Parcel &p, void *response, size_t responselen);
281static int responseStrings(Parcel &p, void *response, size_t responselen);
282static int responseString(Parcel &p, void *response, size_t responselen);
283static int responseVoid(Parcel &p, void *response, size_t responselen);
284static int responseCallList(Parcel &p, void *response, size_t responselen);
285static int responseSMS(Parcel &p, void *response, size_t responselen);
286static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
287static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700288static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800289static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800290static int responseRaw(Parcel &p, void *response, size_t responselen);
291static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700292static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700293static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
294static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700295static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800296static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700297static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
298static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
299static int responseCallRing(Parcel &p, void *response, size_t responselen);
300static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
301static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800302static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700303static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700304static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700305static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800306
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800307static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
308static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
309static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
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)
313extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
314 size_t datalen, RIL_SOCKET_ID socket_id);
315#else
Wink Saville7f856802009-06-09 10:23:37 -0700316extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, 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"
369void RIL_setRilSocketName(char * s) {
370 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 Savillef4c4d362009-04-02 01:37:03 -0700383static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800384 char16_t *s16;
385 size_t s16_len;
386 s16 = strdup8to16(s, &s16_len);
387 p.writeString16(s16, s16_len);
388 free(s16);
389}
390
391
392static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700393memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800394 if (s != NULL) {
395 memset (s, 0, strlen(s));
396 }
397}
398
399void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
400 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700401 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800402 // do nothing -- the data reference lives longer than the Parcel object
403}
404
Wink Saville7f856802009-06-09 10:23:37 -0700405/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800406 * To be called from dispatch thread
407 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700408 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 */
410static void
Etan Cohend3652192014-06-20 08:28:44 -0700411issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800412 RequestInfo *pRI;
413 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700414 /* Hook for current context */
415 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
416 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
417 /* pendingRequestsHook refer to &s_pendingRequests */
418 RequestInfo** pendingRequestsHook = &s_pendingRequests;
419
420#if (SIM_COUNT == 2)
421 if (socket_id == RIL_SOCKET_2) {
422 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
423 pendingRequestsHook = &s_pendingRequests_socket2;
424 }
425#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800426
427 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
428
429 pRI->local = 1;
430 pRI->token = 0xffffffff; // token is not used in this context
431 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700432 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433
Etan Cohend3652192014-06-20 08:28:44 -0700434 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800435 assert (ret == 0);
436
Etan Cohend3652192014-06-20 08:28:44 -0700437 pRI->p_next = *pendingRequestsHook;
438 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800439
Etan Cohend3652192014-06-20 08:28:44 -0700440 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800441 assert (ret == 0);
442
Wink Saville8eb2a122012-11-19 16:05:13 -0800443 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800444
Etan Cohend3652192014-06-20 08:28:44 -0700445 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800446}
447
448
449
450static int
Etan Cohend3652192014-06-20 08:28:44 -0700451processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452 Parcel p;
453 status_t status;
454 int32_t request;
455 int32_t token;
456 RequestInfo *pRI;
457 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700458 /* Hook for current context */
459 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
460 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
461 /* pendingRequestsHook refer to &s_pendingRequests */
462 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463
464 p.setData((uint8_t *) buffer, buflen);
465
466 // status checked at end
467 status = p.readInt32(&request);
468 status = p.readInt32 (&token);
469
Etan Cohend3652192014-06-20 08:28:44 -0700470 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
471
472#if (SIM_COUNT >= 2)
473 if (socket_id == RIL_SOCKET_2) {
474 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
475 pendingRequestsHook = &s_pendingRequests_socket2;
476 }
477#if (SIM_COUNT >= 3)
478 else if (socket_id == RIL_SOCKET_3) {
479 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
480 pendingRequestsHook = &s_pendingRequests_socket3;
481 }
482#endif
483#if (SIM_COUNT >= 4)
484 else if (socket_id == RIL_SOCKET_4) {
485 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
486 pendingRequestsHook = &s_pendingRequests_socket4;
487 }
488#endif
489#endif
490
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800491 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800492 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800493 return 0;
494 }
495
496 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700497 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800498 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800499 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700500 pErr.writeInt32 (RESPONSE_SOLICITED);
501 pErr.writeInt32 (token);
502 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
503
504 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800505 return 0;
506 }
507
508
509 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
510
511 pRI->token = token;
512 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700513 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514
Etan Cohend3652192014-06-20 08:28:44 -0700515 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 assert (ret == 0);
517
Etan Cohend3652192014-06-20 08:28:44 -0700518 pRI->p_next = *pendingRequestsHook;
519 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520
Etan Cohend3652192014-06-20 08:28:44 -0700521 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522 assert (ret == 0);
523
524/* sLastDispatchedToken = token; */
525
Wink Saville7f856802009-06-09 10:23:37 -0700526 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800527
528 return 0;
529}
530
531static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700532invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800533 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 pRI->token, requestToString(pRI->pCI->requestNumber));
535}
536
537/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700538static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700539dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540 clearPrintBuf;
541 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700542 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543}
544
545/** Callee expects const char * */
546static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700547dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800548 status_t status;
549 size_t datalen;
550 size_t stringlen;
551 char *string8 = NULL;
552
553 string8 = strdupReadString(p);
554
555 startRequest;
556 appendPrintBuf("%s%s", printBuf, string8);
557 closeRequest;
558 printRequest(pRI->token, pRI->pCI->requestNumber);
559
Etan Cohend3652192014-06-20 08:28:44 -0700560 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
561 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800562
563#ifdef MEMSET_FREED
564 memsetString(string8);
565#endif
566
567 free(string8);
568 return;
569invalid:
570 invalidCommandBlock(pRI);
571 return;
572}
573
574/** Callee expects const char ** */
575static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700576dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800577 int32_t countStrings;
578 status_t status;
579 size_t datalen;
580 char **pStrings;
581
582 status = p.readInt32 (&countStrings);
583
584 if (status != NO_ERROR) {
585 goto invalid;
586 }
587
588 startRequest;
589 if (countStrings == 0) {
590 // just some non-null pointer
591 pStrings = (char **)alloca(sizeof(char *));
592 datalen = 0;
593 } else if (((int)countStrings) == -1) {
594 pStrings = NULL;
595 datalen = 0;
596 } else {
597 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700598
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800599 pStrings = (char **)alloca(datalen);
600
601 for (int i = 0 ; i < countStrings ; i++) {
602 pStrings[i] = strdupReadString(p);
603 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
604 }
605 }
606 removeLastChar;
607 closeRequest;
608 printRequest(pRI->token, pRI->pCI->requestNumber);
609
Etan Cohend3652192014-06-20 08:28:44 -0700610 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800611
612 if (pStrings != NULL) {
613 for (int i = 0 ; i < countStrings ; i++) {
614#ifdef MEMSET_FREED
615 memsetString (pStrings[i]);
616#endif
617 free(pStrings[i]);
618 }
619
620#ifdef MEMSET_FREED
621 memset(pStrings, 0, datalen);
622#endif
623 }
Wink Saville7f856802009-06-09 10:23:37 -0700624
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800625 return;
626invalid:
627 invalidCommandBlock(pRI);
628 return;
629}
630
631/** Callee expects const int * */
632static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700633dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800634 int32_t count;
635 status_t status;
636 size_t datalen;
637 int *pInts;
638
639 status = p.readInt32 (&count);
640
641 if (status != NO_ERROR || count == 0) {
642 goto invalid;
643 }
644
645 datalen = sizeof(int) * count;
646 pInts = (int *)alloca(datalen);
647
648 startRequest;
649 for (int i = 0 ; i < count ; i++) {
650 int32_t t;
651
652 status = p.readInt32(&t);
653 pInts[i] = (int)t;
654 appendPrintBuf("%s%d,", printBuf, t);
655
656 if (status != NO_ERROR) {
657 goto invalid;
658 }
659 }
660 removeLastChar;
661 closeRequest;
662 printRequest(pRI->token, pRI->pCI->requestNumber);
663
Etan Cohend3652192014-06-20 08:28:44 -0700664 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
665 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800666
667#ifdef MEMSET_FREED
668 memset(pInts, 0, datalen);
669#endif
670
671 return;
672invalid:
673 invalidCommandBlock(pRI);
674 return;
675}
676
677
Wink Saville7f856802009-06-09 10:23:37 -0700678/**
679 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800680 * Payload is:
681 * int32_t status
682 * String pdu
683 */
684static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700685dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800686 RIL_SMS_WriteArgs args;
687 int32_t t;
688 status_t status;
689
Nanik Tolaram4bd5eb52015-02-03 12:50:04 +1100690 ALOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800691 memset (&args, 0, sizeof(args));
692
693 status = p.readInt32(&t);
694 args.status = (int)t;
695
696 args.pdu = strdupReadString(p);
697
698 if (status != NO_ERROR || args.pdu == NULL) {
699 goto invalid;
700 }
701
702 args.smsc = strdupReadString(p);
703
704 startRequest;
705 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
706 (char*)args.pdu, (char*)args.smsc);
707 closeRequest;
708 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700709
Etan Cohend3652192014-06-20 08:28:44 -0700710 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800711
712#ifdef MEMSET_FREED
713 memsetString (args.pdu);
714#endif
715
716 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700717
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800718#ifdef MEMSET_FREED
719 memset(&args, 0, sizeof(args));
720#endif
721
722 return;
723invalid:
724 invalidCommandBlock(pRI);
725 return;
726}
727
Wink Saville7f856802009-06-09 10:23:37 -0700728/**
729 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800730 * Payload is:
731 * String address
732 * int32_t clir
733 */
734static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700735dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800736 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800737 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800738 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800739 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800740 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800741 status_t status;
742
Nanik Tolaram4bd5eb52015-02-03 12:50:04 +1100743 ALOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800744 memset (&dial, 0, sizeof(dial));
745
746 dial.address = strdupReadString(p);
747
748 status = p.readInt32(&t);
749 dial.clir = (int)t;
750
751 if (status != NO_ERROR || dial.address == NULL) {
752 goto invalid;
753 }
754
Wink Saville3a4840b2010-04-07 13:29:58 -0700755 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800756 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800757 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800758 } else {
759 status = p.readInt32(&uusPresent);
760
761 if (status != NO_ERROR) {
762 goto invalid;
763 }
764
765 if (uusPresent == 0) {
766 dial.uusInfo = NULL;
767 } else {
768 int32_t len;
769
770 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
771
772 status = p.readInt32(&t);
773 uusInfo.uusType = (RIL_UUS_Type) t;
774
775 status = p.readInt32(&t);
776 uusInfo.uusDcs = (RIL_UUS_DCS) t;
777
778 status = p.readInt32(&len);
779 if (status != NO_ERROR) {
780 goto invalid;
781 }
782
783 // The java code writes -1 for null arrays
784 if (((int) len) == -1) {
785 uusInfo.uusData = NULL;
786 len = 0;
787 } else {
788 uusInfo.uusData = (char*) p.readInplace(len);
789 }
790
791 uusInfo.uusLength = len;
792 dial.uusInfo = &uusInfo;
793 }
Wink Saville7bce0822010-01-08 15:20:12 -0800794 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800795 }
796
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800797 startRequest;
798 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800799 if (uusPresent) {
800 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
801 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
802 dial.uusInfo->uusLength);
803 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800804 closeRequest;
805 printRequest(pRI->token, pRI->pCI->requestNumber);
806
Etan Cohend3652192014-06-20 08:28:44 -0700807 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800808
809#ifdef MEMSET_FREED
810 memsetString (dial.address);
811#endif
812
813 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700814
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800815#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800816 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800817 memset(&dial, 0, sizeof(dial));
818#endif
819
820 return;
821invalid:
822 invalidCommandBlock(pRI);
823 return;
824}
825
Wink Saville7f856802009-06-09 10:23:37 -0700826/**
827 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800828 * Payload is:
829 * int32_t command
830 * int32_t fileid
831 * String path
832 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700833 * String data
834 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800835 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800836 */
837static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700838dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800839 union RIL_SIM_IO {
840 RIL_SIM_IO_v6 v6;
841 RIL_SIM_IO_v5 v5;
842 } simIO;
843
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800844 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800845 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800846 status_t status;
847
Nanik Tolaram4bd5eb52015-02-03 12:50:04 +1100848 ALOGD("dispatchSIM_IO");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800849 memset (&simIO, 0, sizeof(simIO));
850
Wink Saville7f856802009-06-09 10:23:37 -0700851 // note we only check status at the end
852
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800853 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800854 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855
856 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800857 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800858
Wink Savillec0114b32011-02-18 10:14:07 -0800859 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800860
861 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800862 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863
864 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800865 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866
867 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800868 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869
Wink Savillec0114b32011-02-18 10:14:07 -0800870 simIO.v6.data = strdupReadString(p);
871 simIO.v6.pin2 = strdupReadString(p);
872 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873
874 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800875 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
876 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
877 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
878 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800879 closeRequest;
880 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700881
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800882 if (status != NO_ERROR) {
883 goto invalid;
884 }
885
Wink Savillec0114b32011-02-18 10:14:07 -0800886 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700887 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888
889#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800890 memsetString (simIO.v6.path);
891 memsetString (simIO.v6.data);
892 memsetString (simIO.v6.pin2);
893 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800894#endif
895
Wink Savillec0114b32011-02-18 10:14:07 -0800896 free (simIO.v6.path);
897 free (simIO.v6.data);
898 free (simIO.v6.pin2);
899 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700900
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800901#ifdef MEMSET_FREED
902 memset(&simIO, 0, sizeof(simIO));
903#endif
904
905 return;
906invalid:
907 invalidCommandBlock(pRI);
908 return;
909}
910
911/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800912 * Callee expects const RIL_SIM_APDU *
913 * Payload is:
914 * int32_t sessionid
915 * int32_t cla
916 * int32_t instruction
917 * int32_t p1, p2, p3
918 * String data
919 */
920static void
921dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
922 int32_t t;
923 status_t status;
924 RIL_SIM_APDU apdu;
925
Nanik Tolaram4bd5eb52015-02-03 12:50:04 +1100926 ALOGD("dispatchSIM_APDU");
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800927 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
928
929 // Note we only check status at the end. Any single failure leads to
930 // subsequent reads filing.
931 status = p.readInt32(&t);
932 apdu.sessionid = (int)t;
933
934 status = p.readInt32(&t);
935 apdu.cla = (int)t;
936
937 status = p.readInt32(&t);
938 apdu.instruction = (int)t;
939
940 status = p.readInt32(&t);
941 apdu.p1 = (int)t;
942
943 status = p.readInt32(&t);
944 apdu.p2 = (int)t;
945
946 status = p.readInt32(&t);
947 apdu.p3 = (int)t;
948
949 apdu.data = strdupReadString(p);
950
951 startRequest;
952 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
953 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
954 apdu.p3, (char*)apdu.data);
955 closeRequest;
956 printRequest(pRI->token, pRI->pCI->requestNumber);
957
958 if (status != NO_ERROR) {
959 goto invalid;
960 }
961
Etan Cohend3652192014-06-20 08:28:44 -0700962 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800963
964#ifdef MEMSET_FREED
965 memsetString(apdu.data);
966#endif
967 free(apdu.data);
968
969#ifdef MEMSET_FREED
970 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
971#endif
972
973 return;
974invalid:
975 invalidCommandBlock(pRI);
976 return;
977}
978
979
980/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800981 * Callee expects const RIL_CallForwardInfo *
982 * Payload is:
983 * int32_t status/action
984 * int32_t reason
985 * int32_t serviceCode
986 * int32_t toa
987 * String number (0 length -> null)
988 * int32_t timeSeconds
989 */
Wink Saville7f856802009-06-09 10:23:37 -0700990static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700991dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800992 RIL_CallForwardInfo cff;
993 int32_t t;
994 status_t status;
995
Nanik Tolaram4bd5eb52015-02-03 12:50:04 +1100996 ALOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800997 memset (&cff, 0, sizeof(cff));
998
Wink Saville7f856802009-06-09 10:23:37 -0700999 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001000
1001 status = p.readInt32(&t);
1002 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001003
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001004 status = p.readInt32(&t);
1005 cff.reason = (int)t;
1006
1007 status = p.readInt32(&t);
1008 cff.serviceClass = (int)t;
1009
1010 status = p.readInt32(&t);
1011 cff.toa = (int)t;
1012
1013 cff.number = strdupReadString(p);
1014
1015 status = p.readInt32(&t);
1016 cff.timeSeconds = (int)t;
1017
1018 if (status != NO_ERROR) {
1019 goto invalid;
1020 }
1021
1022 // special case: number 0-length fields is null
1023
1024 if (cff.number != NULL && strlen (cff.number) == 0) {
1025 cff.number = NULL;
1026 }
1027
1028 startRequest;
1029 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1030 cff.status, cff.reason, cff.serviceClass, cff.toa,
1031 (char*)cff.number, cff.timeSeconds);
1032 closeRequest;
1033 printRequest(pRI->token, pRI->pCI->requestNumber);
1034
Etan Cohend3652192014-06-20 08:28:44 -07001035 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001036
1037#ifdef MEMSET_FREED
1038 memsetString(cff.number);
1039#endif
1040
1041 free (cff.number);
1042
1043#ifdef MEMSET_FREED
1044 memset(&cff, 0, sizeof(cff));
1045#endif
1046
1047 return;
1048invalid:
1049 invalidCommandBlock(pRI);
1050 return;
1051}
1052
1053
Wink Saville7f856802009-06-09 10:23:37 -07001054static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001055dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001056 int32_t len;
1057 status_t status;
1058 const void *data;
1059
1060 status = p.readInt32(&len);
1061
1062 if (status != NO_ERROR) {
1063 goto invalid;
1064 }
1065
1066 // The java code writes -1 for null arrays
1067 if (((int)len) == -1) {
1068 data = NULL;
1069 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001070 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001071
1072 data = p.readInplace(len);
1073
1074 startRequest;
1075 appendPrintBuf("%sraw_size=%d", printBuf, len);
1076 closeRequest;
1077 printRequest(pRI->token, pRI->pCI->requestNumber);
1078
Etan Cohend3652192014-06-20 08:28:44 -07001079 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001080
1081 return;
1082invalid:
1083 invalidCommandBlock(pRI);
1084 return;
1085}
1086
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001087static status_t
1088constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001089 int32_t t;
1090 uint8_t ut;
1091 status_t status;
1092 int32_t digitCount;
1093 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001094
Wink Savillef4c4d362009-04-02 01:37:03 -07001095 memset(&rcsm, 0, sizeof(rcsm));
1096
1097 status = p.readInt32(&t);
1098 rcsm.uTeleserviceID = (int) t;
1099
1100 status = p.read(&ut,sizeof(ut));
1101 rcsm.bIsServicePresent = (uint8_t) ut;
1102
1103 status = p.readInt32(&t);
1104 rcsm.uServicecategory = (int) t;
1105
1106 status = p.readInt32(&t);
1107 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1108
1109 status = p.readInt32(&t);
1110 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1111
1112 status = p.readInt32(&t);
1113 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1114
1115 status = p.readInt32(&t);
1116 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1117
1118 status = p.read(&ut,sizeof(ut));
1119 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1120
1121 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1122 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1123 status = p.read(&ut,sizeof(ut));
1124 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1125 }
1126
Wink Saville7f856802009-06-09 10:23:37 -07001127 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001128 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1129
Wink Saville7f856802009-06-09 10:23:37 -07001130 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001131 rcsm.sSubAddress.odd = (uint8_t) ut;
1132
1133 status = p.read(&ut,sizeof(ut));
1134 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1135
1136 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001137 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1138 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001139 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1140 }
1141
Wink Saville7f856802009-06-09 10:23:37 -07001142 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001143 rcsm.uBearerDataLen = (int) t;
1144
1145 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001146 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1147 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001148 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1149 }
1150
1151 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001152 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001153 }
1154
1155 startRequest;
1156 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001157 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001158 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001159 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001160 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001161
Wink Savillef4c4d362009-04-02 01:37:03 -07001162 printRequest(pRI->token, pRI->pCI->requestNumber);
1163
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001164 return status;
1165}
1166
1167static void
1168dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1169 RIL_CDMA_SMS_Message rcsm;
1170
1171 ALOGD("dispatchCdmaSms");
1172 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1173 goto invalid;
1174 }
1175
Etan Cohend3652192014-06-20 08:28:44 -07001176 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001177
1178#ifdef MEMSET_FREED
1179 memset(&rcsm, 0, sizeof(rcsm));
1180#endif
1181
1182 return;
1183
1184invalid:
1185 invalidCommandBlock(pRI);
1186 return;
1187}
1188
Wink Saville7f856802009-06-09 10:23:37 -07001189static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001190dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1191 RIL_IMS_SMS_Message rism;
1192 RIL_CDMA_SMS_Message rcsm;
1193
1194 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1195
1196 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1197 goto invalid;
1198 }
1199 memset(&rism, 0, sizeof(rism));
1200 rism.tech = RADIO_TECH_3GPP2;
1201 rism.retry = retry;
1202 rism.messageRef = messageRef;
1203 rism.message.cdmaMessage = &rcsm;
1204
Etan Cohend3652192014-06-20 08:28:44 -07001205 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001206 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001207 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001208
1209#ifdef MEMSET_FREED
1210 memset(&rcsm, 0, sizeof(rcsm));
1211 memset(&rism, 0, sizeof(rism));
1212#endif
1213
1214 return;
1215
1216invalid:
1217 invalidCommandBlock(pRI);
1218 return;
1219}
1220
1221static void
1222dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1223 RIL_IMS_SMS_Message rism;
1224 int32_t countStrings;
1225 status_t status;
1226 size_t datalen;
1227 char **pStrings;
1228 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1229
1230 status = p.readInt32 (&countStrings);
1231
1232 if (status != NO_ERROR) {
1233 goto invalid;
1234 }
1235
1236 memset(&rism, 0, sizeof(rism));
1237 rism.tech = RADIO_TECH_3GPP;
1238 rism.retry = retry;
1239 rism.messageRef = messageRef;
1240
1241 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001242 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1243 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001244 if (countStrings == 0) {
1245 // just some non-null pointer
1246 pStrings = (char **)alloca(sizeof(char *));
1247 datalen = 0;
1248 } else if (((int)countStrings) == -1) {
1249 pStrings = NULL;
1250 datalen = 0;
1251 } else {
1252 datalen = sizeof(char *) * countStrings;
1253
1254 pStrings = (char **)alloca(datalen);
1255
1256 for (int i = 0 ; i < countStrings ; i++) {
1257 pStrings[i] = strdupReadString(p);
1258 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1259 }
1260 }
1261 removeLastChar;
1262 closeRequest;
1263 printRequest(pRI->token, pRI->pCI->requestNumber);
1264
1265 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001266 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001267 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001268 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001269
1270 if (pStrings != NULL) {
1271 for (int i = 0 ; i < countStrings ; i++) {
1272#ifdef MEMSET_FREED
1273 memsetString (pStrings[i]);
1274#endif
1275 free(pStrings[i]);
1276 }
1277
1278#ifdef MEMSET_FREED
1279 memset(pStrings, 0, datalen);
1280#endif
1281 }
1282
1283#ifdef MEMSET_FREED
1284 memset(&rism, 0, sizeof(rism));
1285#endif
1286 return;
1287invalid:
1288 ALOGE("dispatchImsGsmSms invalid block");
1289 invalidCommandBlock(pRI);
1290 return;
1291}
1292
1293static void
1294dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1295 int32_t t;
1296 status_t status = p.readInt32(&t);
1297 RIL_RadioTechnologyFamily format;
1298 uint8_t retry;
1299 int32_t messageRef;
1300
1301 ALOGD("dispatchImsSms");
1302 if (status != NO_ERROR) {
1303 goto invalid;
1304 }
1305 format = (RIL_RadioTechnologyFamily) t;
1306
1307 // read retry field
1308 status = p.read(&retry,sizeof(retry));
1309 if (status != NO_ERROR) {
1310 goto invalid;
1311 }
1312 // read messageRef field
1313 status = p.read(&messageRef,sizeof(messageRef));
1314 if (status != NO_ERROR) {
1315 goto invalid;
1316 }
1317
1318 if (RADIO_TECH_3GPP == format) {
1319 dispatchImsGsmSms(p, pRI, retry, messageRef);
1320 } else if (RADIO_TECH_3GPP2 == format) {
1321 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1322 } else {
1323 ALOGE("requestImsSendSMS invalid format value =%d", format);
1324 }
1325
1326 return;
1327
1328invalid:
1329 invalidCommandBlock(pRI);
1330 return;
1331}
1332
1333static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001334dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1335 RIL_CDMA_SMS_Ack rcsa;
1336 int32_t t;
1337 status_t status;
1338 int32_t digitCount;
1339
Nanik Tolaram4bd5eb52015-02-03 12:50:04 +11001340 ALOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001341 memset(&rcsa, 0, sizeof(rcsa));
1342
1343 status = p.readInt32(&t);
1344 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1345
1346 status = p.readInt32(&t);
1347 rcsa.uSMSCauseCode = (int) t;
1348
1349 if (status != NO_ERROR) {
1350 goto invalid;
1351 }
1352
1353 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001354 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1355 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001356 closeRequest;
1357
1358 printRequest(pRI->token, pRI->pCI->requestNumber);
1359
Etan Cohend3652192014-06-20 08:28:44 -07001360 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001361
1362#ifdef MEMSET_FREED
1363 memset(&rcsa, 0, sizeof(rcsa));
1364#endif
1365
1366 return;
1367
1368invalid:
1369 invalidCommandBlock(pRI);
1370 return;
1371}
1372
Wink Savillea592eeb2009-05-22 13:26:36 -07001373static void
1374dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1375 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001376 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001377 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001378
Wink Savillea592eeb2009-05-22 13:26:36 -07001379 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001380 if (status != NO_ERROR) {
1381 goto invalid;
1382 }
1383
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001384 {
1385 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1386 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001387
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001388 startRequest;
1389 for (int i = 0 ; i < num ; i++ ) {
1390 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001391
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001392 status = p.readInt32(&t);
1393 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001394
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001395 status = p.readInt32(&t);
1396 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001397
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001398 status = p.readInt32(&t);
1399 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001400
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001401 status = p.readInt32(&t);
1402 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001403
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001404 status = p.readInt32(&t);
1405 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001406
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001407 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1408 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1409 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1410 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1411 gsmBci[i].selected);
1412 }
1413 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001414
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001415 if (status != NO_ERROR) {
1416 goto invalid;
1417 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001418
Etan Cohend3652192014-06-20 08:28:44 -07001419 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 gsmBciPtrs,
1421 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001422 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001423
1424#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001425 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1426 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001427#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001428 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001429
1430 return;
1431
1432invalid:
1433 invalidCommandBlock(pRI);
1434 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001435}
Wink Savillef4c4d362009-04-02 01:37:03 -07001436
Wink Savillea592eeb2009-05-22 13:26:36 -07001437static void
1438dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1439 int32_t t;
1440 status_t status;
1441 int32_t num;
1442
1443 status = p.readInt32(&num);
1444 if (status != NO_ERROR) {
1445 goto invalid;
1446 }
1447
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001448 {
1449 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1450 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001451
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001452 startRequest;
1453 for (int i = 0 ; i < num ; i++ ) {
1454 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001455
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001456 status = p.readInt32(&t);
1457 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001458
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001459 status = p.readInt32(&t);
1460 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001461
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001462 status = p.readInt32(&t);
1463 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001464
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001465 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1466 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1467 cdmaBci[i].language, cdmaBci[i].selected);
1468 }
1469 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001470
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001471 if (status != NO_ERROR) {
1472 goto invalid;
1473 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001474
Etan Cohend3652192014-06-20 08:28:44 -07001475 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 cdmaBciPtrs,
1477 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001478 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
1480#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1482 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001483#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
1486 return;
1487
1488invalid:
1489 invalidCommandBlock(pRI);
1490 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001491}
1492
1493static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1494 RIL_CDMA_SMS_WriteArgs rcsw;
1495 int32_t t;
1496 uint32_t ut;
1497 uint8_t uct;
1498 status_t status;
1499 int32_t digitCount;
1500
1501 memset(&rcsw, 0, sizeof(rcsw));
1502
1503 status = p.readInt32(&t);
1504 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001505
Wink Savillef4c4d362009-04-02 01:37:03 -07001506 status = p.readInt32(&t);
1507 rcsw.message.uTeleserviceID = (int) t;
1508
1509 status = p.read(&uct,sizeof(uct));
1510 rcsw.message.bIsServicePresent = (uint8_t) uct;
1511
1512 status = p.readInt32(&t);
1513 rcsw.message.uServicecategory = (int) t;
1514
1515 status = p.readInt32(&t);
1516 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1517
1518 status = p.readInt32(&t);
1519 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1520
1521 status = p.readInt32(&t);
1522 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1523
1524 status = p.readInt32(&t);
1525 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1526
1527 status = p.read(&uct,sizeof(uct));
1528 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1529
1530 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1531 status = p.read(&uct,sizeof(uct));
1532 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1533 }
1534
Wink Savillea592eeb2009-05-22 13:26:36 -07001535 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001536 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1537
Wink Savillea592eeb2009-05-22 13:26:36 -07001538 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001539 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1540
1541 status = p.read(&uct,sizeof(uct));
1542 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1543
1544 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001545 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001546 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1547 }
1548
Wink Savillea592eeb2009-05-22 13:26:36 -07001549 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001550 rcsw.message.uBearerDataLen = (int) t;
1551
1552 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001553 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001554 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1555 }
1556
1557 if (status != NO_ERROR) {
1558 goto invalid;
1559 }
1560
1561 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001562 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1563 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1564 message.sAddress.number_mode=%d, \
1565 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001566 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001567 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1568 rcsw.message.sAddress.number_mode,
1569 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001570 closeRequest;
1571
1572 printRequest(pRI->token, pRI->pCI->requestNumber);
1573
Etan Cohend3652192014-06-20 08:28:44 -07001574 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001575
1576#ifdef MEMSET_FREED
1577 memset(&rcsw, 0, sizeof(rcsw));
1578#endif
1579
1580 return;
1581
1582invalid:
1583 invalidCommandBlock(pRI);
1584 return;
1585
1586}
1587
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001588// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1589// Version 4 of the RIL interface adds a new PDP type parameter to support
1590// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1591// RIL, remove the parameter from the request.
1592static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1593 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1594 const int numParamsRilV3 = 6;
1595
1596 // The first bytes of the RIL parcel contain the request number and the
1597 // serial number - see processCommandBuffer(). Copy them over too.
1598 int pos = p.dataPosition();
1599
1600 int numParams = p.readInt32();
1601 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1602 Parcel p2;
1603 p2.appendFrom(&p, 0, pos);
1604 p2.writeInt32(numParamsRilV3);
1605 for(int i = 0; i < numParamsRilV3; i++) {
1606 p2.writeString16(p.readString16());
1607 }
1608 p2.setDataPosition(pos);
1609 dispatchStrings(p2, pRI);
1610 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001611 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001612 dispatchStrings(p, pRI);
1613 }
1614}
1615
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001616// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1617// When all RILs handle this request, this function can be removed and
1618// the request can be sent directly to the RIL using dispatchVoid.
1619static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001620 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001621
1622 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1623 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1624 }
1625
1626 // RILs that support RADIO_STATE_ON should support this request.
1627 if (RADIO_STATE_ON == state) {
1628 dispatchVoid(p, pRI);
1629 return;
1630 }
1631
1632 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1633 // will not support this new request either and decode Voice Radio Technology
1634 // from Radio State
1635 voiceRadioTech = decodeVoiceRadioTechnology(state);
1636
1637 if (voiceRadioTech < 0)
1638 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1639 else
1640 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1641}
1642
1643// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1644// When all RILs handle this request, this function can be removed and
1645// the request can be sent directly to the RIL using dispatchVoid.
1646static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001647 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001648
1649 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1650 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1651 }
1652
1653 // RILs that support RADIO_STATE_ON should support this request.
1654 if (RADIO_STATE_ON == state) {
1655 dispatchVoid(p, pRI);
1656 return;
1657 }
1658
1659 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1660 // will not support this new request either and decode CDMA Subscription Source
1661 // from Radio State
1662 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1663
1664 if (cdmaSubscriptionSource < 0)
1665 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1666 else
1667 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1668}
1669
Sungmin Choi75697532013-04-26 15:04:45 -07001670static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1671{
1672 RIL_InitialAttachApn pf;
1673 int32_t t;
1674 status_t status;
1675
1676 memset(&pf, 0, sizeof(pf));
1677
1678 pf.apn = strdupReadString(p);
1679 pf.protocol = strdupReadString(p);
1680
1681 status = p.readInt32(&t);
1682 pf.authtype = (int) t;
1683
1684 pf.username = strdupReadString(p);
1685 pf.password = strdupReadString(p);
1686
1687 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001688 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1689 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001690 closeRequest;
1691 printRequest(pRI->token, pRI->pCI->requestNumber);
1692
1693 if (status != NO_ERROR) {
1694 goto invalid;
1695 }
Etan Cohend3652192014-06-20 08:28:44 -07001696 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001697
1698#ifdef MEMSET_FREED
1699 memsetString(pf.apn);
1700 memsetString(pf.protocol);
1701 memsetString(pf.username);
1702 memsetString(pf.password);
1703#endif
1704
1705 free(pf.apn);
1706 free(pf.protocol);
1707 free(pf.username);
1708 free(pf.password);
1709
1710#ifdef MEMSET_FREED
1711 memset(&pf, 0, sizeof(pf));
1712#endif
1713
1714 return;
1715invalid:
1716 invalidCommandBlock(pRI);
1717 return;
1718}
1719
Jake Hamby8a4a2332014-01-15 13:12:05 -08001720static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1721 RIL_NV_ReadItem nvri;
1722 int32_t t;
1723 status_t status;
1724
1725 memset(&nvri, 0, sizeof(nvri));
1726
1727 status = p.readInt32(&t);
1728 nvri.itemID = (RIL_NV_Item) t;
1729
1730 if (status != NO_ERROR) {
1731 goto invalid;
1732 }
1733
1734 startRequest;
1735 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1736 closeRequest;
1737
1738 printRequest(pRI->token, pRI->pCI->requestNumber);
1739
Etan Cohend3652192014-06-20 08:28:44 -07001740 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001741
1742#ifdef MEMSET_FREED
1743 memset(&nvri, 0, sizeof(nvri));
1744#endif
1745
1746 return;
1747
1748invalid:
1749 invalidCommandBlock(pRI);
1750 return;
1751}
1752
1753static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1754 RIL_NV_WriteItem nvwi;
1755 int32_t t;
1756 status_t status;
1757
1758 memset(&nvwi, 0, sizeof(nvwi));
1759
1760 status = p.readInt32(&t);
1761 nvwi.itemID = (RIL_NV_Item) t;
1762
1763 nvwi.value = strdupReadString(p);
1764
1765 if (status != NO_ERROR || nvwi.value == NULL) {
1766 goto invalid;
1767 }
1768
1769 startRequest;
1770 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1771 nvwi.value);
1772 closeRequest;
1773
1774 printRequest(pRI->token, pRI->pCI->requestNumber);
1775
Etan Cohend3652192014-06-20 08:28:44 -07001776 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001777
1778#ifdef MEMSET_FREED
1779 memsetString(nvwi.value);
1780#endif
1781
1782 free(nvwi.value);
1783
1784#ifdef MEMSET_FREED
1785 memset(&nvwi, 0, sizeof(nvwi));
1786#endif
1787
1788 return;
1789
1790invalid:
1791 invalidCommandBlock(pRI);
1792 return;
1793}
1794
1795
Etan Cohend3652192014-06-20 08:28:44 -07001796static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1797 RIL_SelectUiccSub uicc_sub;
1798 status_t status;
1799 int32_t t;
1800 memset(&uicc_sub, 0, sizeof(uicc_sub));
1801
1802 status = p.readInt32(&t);
1803 if (status != NO_ERROR) {
1804 goto invalid;
1805 }
1806 uicc_sub.slot = (int) t;
1807
1808 status = p.readInt32(&t);
1809 if (status != NO_ERROR) {
1810 goto invalid;
1811 }
1812 uicc_sub.app_index = (int) t;
1813
1814 status = p.readInt32(&t);
1815 if (status != NO_ERROR) {
1816 goto invalid;
1817 }
1818 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1819
1820 status = p.readInt32(&t);
1821 if (status != NO_ERROR) {
1822 goto invalid;
1823 }
1824 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1825
1826 startRequest;
1827 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1828 uicc_sub.act_status);
1829 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1830 uicc_sub.app_index, uicc_sub.act_status);
1831 closeRequest;
1832 printRequest(pRI->token, pRI->pCI->requestNumber);
1833
1834 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1835
1836#ifdef MEMSET_FREED
1837 memset(&uicc_sub, 0, sizeof(uicc_sub));
1838#endif
1839 return;
1840
1841invalid:
1842 invalidCommandBlock(pRI);
1843 return;
1844}
1845
Amit Mahajan90530a62014-07-01 15:54:08 -07001846static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1847{
1848 RIL_SimAuthentication pf;
1849 int32_t t;
1850 status_t status;
1851
1852 memset(&pf, 0, sizeof(pf));
1853
1854 status = p.readInt32(&t);
1855 pf.authContext = (int) t;
1856 pf.authData = strdupReadString(p);
1857 pf.aid = strdupReadString(p);
1858
1859 startRequest;
1860 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1861 closeRequest;
1862 printRequest(pRI->token, pRI->pCI->requestNumber);
1863
1864 if (status != NO_ERROR) {
1865 goto invalid;
1866 }
1867 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1868
1869#ifdef MEMSET_FREED
1870 memsetString(pf.authData);
1871 memsetString(pf.aid);
1872#endif
1873
1874 free(pf.authData);
1875 free(pf.aid);
1876
1877#ifdef MEMSET_FREED
1878 memset(&pf, 0, sizeof(pf));
1879#endif
1880
1881 return;
1882invalid:
1883 invalidCommandBlock(pRI);
1884 return;
1885}
1886
Amit Mahajanc796e222014-08-13 16:54:01 +00001887static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1888 int32_t t;
1889 status_t status;
1890 int32_t num;
1891
1892 status = p.readInt32(&num);
1893 if (status != NO_ERROR) {
1894 goto invalid;
1895 }
1896
1897 {
1898 RIL_DataProfileInfo dataProfiles[num];
1899 RIL_DataProfileInfo *dataProfilePtrs[num];
1900
1901 startRequest;
1902 for (int i = 0 ; i < num ; i++ ) {
1903 dataProfilePtrs[i] = &dataProfiles[i];
1904
1905 status = p.readInt32(&t);
1906 dataProfiles[i].profileId = (int) t;
1907
1908 dataProfiles[i].apn = strdupReadString(p);
1909 dataProfiles[i].protocol = strdupReadString(p);
1910 status = p.readInt32(&t);
1911 dataProfiles[i].authType = (int) t;
1912
1913 dataProfiles[i].user = strdupReadString(p);
1914 dataProfiles[i].password = strdupReadString(p);
1915
1916 status = p.readInt32(&t);
1917 dataProfiles[i].type = (int) t;
1918
1919 status = p.readInt32(&t);
1920 dataProfiles[i].maxConnsTime = (int) t;
1921 status = p.readInt32(&t);
1922 dataProfiles[i].maxConns = (int) t;
1923 status = p.readInt32(&t);
1924 dataProfiles[i].waitTime = (int) t;
1925
1926 status = p.readInt32(&t);
1927 dataProfiles[i].enabled = (int) t;
1928
1929 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1930 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1931 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1932 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1933 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1934 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1935 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1936 }
1937 closeRequest;
1938 printRequest(pRI->token, pRI->pCI->requestNumber);
1939
1940 if (status != NO_ERROR) {
1941 goto invalid;
1942 }
1943 CALL_ONREQUEST(pRI->pCI->requestNumber,
1944 dataProfilePtrs,
1945 num * sizeof(RIL_DataProfileInfo *),
1946 pRI, pRI->socket_id);
1947
1948#ifdef MEMSET_FREED
1949 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1950 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1951#endif
1952 }
1953
1954 return;
1955
1956invalid:
1957 invalidCommandBlock(pRI);
1958 return;
1959}
1960
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001961static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001962blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07001963 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001964 const uint8_t *toWrite;
1965
1966 toWrite = (const uint8_t *)buffer;
1967
1968 while (writeOffset < len) {
1969 ssize_t written;
1970 do {
1971 written = write (fd, toWrite + writeOffset,
1972 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05301973 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001974
1975 if (written >= 0) {
1976 writeOffset += written;
1977 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08001978 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001979 close(fd);
1980 return -1;
1981 }
1982 }
1983
1984 return 0;
1985}
1986
1987static int
Etan Cohend3652192014-06-20 08:28:44 -07001988sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1989 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001990 int ret;
1991 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07001992 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001993
Etan Cohend3652192014-06-20 08:28:44 -07001994 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1995
1996#if (SIM_COUNT >= 2)
1997 if (socket_id == RIL_SOCKET_2) {
1998 fd = s_ril_param_socket2.fdCommand;
1999 writeMutexHook = &s_writeMutex_socket2;
2000 }
2001#if (SIM_COUNT >= 3)
2002 else if (socket_id == RIL_SOCKET_3) {
2003 fd = s_ril_param_socket3.fdCommand;
2004 writeMutexHook = &s_writeMutex_socket3;
2005 }
2006#endif
2007#if (SIM_COUNT >= 4)
2008 else if (socket_id == RIL_SOCKET_4) {
2009 fd = s_ril_param_socket4.fdCommand;
2010 writeMutexHook = &s_writeMutex_socket4;
2011 }
2012#endif
2013#endif
2014 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002015 return -1;
2016 }
2017
2018 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002019 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002020 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2021
2022 return -1;
2023 }
Wink Saville7f856802009-06-09 10:23:37 -07002024
Etan Cohend3652192014-06-20 08:28:44 -07002025 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002026
2027 header = htonl(dataSize);
2028
2029 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2030
2031 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002032 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002033 return ret;
2034 }
2035
Kennyee1fadc2009-08-13 00:45:53 +08002036 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002037
2038 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002039 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002040 return ret;
2041 }
2042
Etan Cohend3652192014-06-20 08:28:44 -07002043 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002044
2045 return 0;
2046}
2047
2048static int
Etan Cohend3652192014-06-20 08:28:44 -07002049sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002050 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002051 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002052}
2053
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002054/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002055
2056static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002057responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002058 int numInts;
2059
2060 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002061 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002062 return RIL_ERRNO_INVALID_RESPONSE;
2063 }
2064 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002065 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002066 (int)responselen, (int)sizeof(int));
2067 return RIL_ERRNO_INVALID_RESPONSE;
2068 }
2069
2070 int *p_int = (int *) response;
2071
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002072 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002073 p.writeInt32 (numInts);
2074
2075 /* each int*/
2076 startResponse;
2077 for (int i = 0 ; i < numInts ; i++) {
2078 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2079 p.writeInt32(p_int[i]);
2080 }
2081 removeLastChar;
2082 closeResponse;
2083
2084 return 0;
2085}
2086
Wink Saville43808972011-01-13 17:39:51 -08002087/** response is a char **, pointing to an array of char *'s
2088 The parcel will begin with the version */
2089static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2090 p.writeInt32(version);
2091 return responseStrings(p, response, responselen);
2092}
2093
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002094/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002095static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002096 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002097
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002098 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002099 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100 return RIL_ERRNO_INVALID_RESPONSE;
2101 }
2102 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002103 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002104 (int)responselen, (int)sizeof(char *));
2105 return RIL_ERRNO_INVALID_RESPONSE;
2106 }
2107
2108 if (response == NULL) {
2109 p.writeInt32 (0);
2110 } else {
2111 char **p_cur = (char **) response;
2112
2113 numStrings = responselen / sizeof(char *);
2114 p.writeInt32 (numStrings);
2115
2116 /* each string*/
2117 startResponse;
2118 for (int i = 0 ; i < numStrings ; i++) {
2119 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2120 writeStringToParcel (p, p_cur[i]);
2121 }
2122 removeLastChar;
2123 closeResponse;
2124 }
2125 return 0;
2126}
2127
2128
2129/**
Wink Saville7f856802009-06-09 10:23:37 -07002130 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002131 * FIXME currently ignores responselen
2132 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002133static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002134 /* one string only */
2135 startResponse;
2136 appendPrintBuf("%s%s", printBuf, (char*)response);
2137 closeResponse;
2138
2139 writeStringToParcel(p, (const char *)response);
2140
2141 return 0;
2142}
2143
Wink Savillef4c4d362009-04-02 01:37:03 -07002144static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002145 startResponse;
2146 removeLastChar;
2147 return 0;
2148}
2149
Wink Savillef4c4d362009-04-02 01:37:03 -07002150static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002151 int num;
2152
2153 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002154 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002155 return RIL_ERRNO_INVALID_RESPONSE;
2156 }
2157
2158 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002159 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002160 (int)responselen, (int)sizeof (RIL_Call *));
2161 return RIL_ERRNO_INVALID_RESPONSE;
2162 }
2163
2164 startResponse;
2165 /* number of call info's */
2166 num = responselen / sizeof(RIL_Call *);
2167 p.writeInt32(num);
2168
2169 for (int i = 0 ; i < num ; i++) {
2170 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2171 /* each call info */
2172 p.writeInt32(p_cur->state);
2173 p.writeInt32(p_cur->index);
2174 p.writeInt32(p_cur->toa);
2175 p.writeInt32(p_cur->isMpty);
2176 p.writeInt32(p_cur->isMT);
2177 p.writeInt32(p_cur->als);
2178 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002179 p.writeInt32(p_cur->isVoicePrivacy);
2180 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002181 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002182 writeStringToParcel(p, p_cur->name);
2183 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002184 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002185 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2186 p.writeInt32(0); /* UUS Information is absent */
2187 } else {
2188 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2189 p.writeInt32(1); /* UUS Information is present */
2190 p.writeInt32(uusInfo->uusType);
2191 p.writeInt32(uusInfo->uusDcs);
2192 p.writeInt32(uusInfo->uusLength);
2193 p.write(uusInfo->uusData, uusInfo->uusLength);
2194 }
Wink Saville3d54e742009-05-18 18:00:44 -07002195 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002196 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002197 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002198 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002199 p_cur->toa);
2200 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2201 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002202 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002203 (p_cur->isMT)?"mt":"mo",
2204 p_cur->als,
2205 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002206 (p_cur->isVoicePrivacy)?"evp":"noevp");
2207 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2208 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002209 p_cur->number,
2210 p_cur->numberPresentation,
2211 p_cur->name,
2212 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002213 }
2214 removeLastChar;
2215 closeResponse;
2216
2217 return 0;
2218}
2219
Wink Savillef4c4d362009-04-02 01:37:03 -07002220static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002221 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002222 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002223 return RIL_ERRNO_INVALID_RESPONSE;
2224 }
2225
2226 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002227 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002228 (int)responselen, (int)sizeof (RIL_SMS_Response));
2229 return RIL_ERRNO_INVALID_RESPONSE;
2230 }
2231
2232 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2233
2234 p.writeInt32(p_cur->messageRef);
2235 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002236 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002237
2238 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002239 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2240 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002241 closeResponse;
2242
2243 return 0;
2244}
2245
Wink Savillec0114b32011-02-18 10:14:07 -08002246static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002247{
2248 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002249 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002250 return RIL_ERRNO_INVALID_RESPONSE;
2251 }
2252
Wink Savillec0114b32011-02-18 10:14:07 -08002253 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002254 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002255 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002256 return RIL_ERRNO_INVALID_RESPONSE;
2257 }
2258
Amit Mahajan52500162014-07-29 17:36:48 -07002259 // Write version
2260 p.writeInt32(4);
2261
Wink Savillec0114b32011-02-18 10:14:07 -08002262 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002263 p.writeInt32(num);
2264
Wink Savillec0114b32011-02-18 10:14:07 -08002265 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002266 startResponse;
2267 int i;
2268 for (i = 0; i < num; i++) {
2269 p.writeInt32(p_cur[i].cid);
2270 p.writeInt32(p_cur[i].active);
2271 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002272 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002273 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002274 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002275 p_cur[i].cid,
2276 (p_cur[i].active==0)?"down":"up",
2277 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002278 (char*)p_cur[i].address);
2279 }
2280 removeLastChar;
2281 closeResponse;
2282
2283 return 0;
2284}
2285
Etan Cohend3652192014-06-20 08:28:44 -07002286static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2287{
Amit Mahajan52500162014-07-29 17:36:48 -07002288 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002289 RLOGE("invalid response: NULL");
2290 return RIL_ERRNO_INVALID_RESPONSE;
2291 }
2292
2293 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002294 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002295 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2296 return RIL_ERRNO_INVALID_RESPONSE;
2297 }
2298
Amit Mahajan52500162014-07-29 17:36:48 -07002299 // Write version
2300 p.writeInt32(6);
2301
Etan Cohend3652192014-06-20 08:28:44 -07002302 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2303 p.writeInt32(num);
2304
2305 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2306 startResponse;
2307 int i;
2308 for (i = 0; i < num; i++) {
2309 p.writeInt32((int)p_cur[i].status);
2310 p.writeInt32(p_cur[i].suggestedRetryTime);
2311 p.writeInt32(p_cur[i].cid);
2312 p.writeInt32(p_cur[i].active);
2313 writeStringToParcel(p, p_cur[i].type);
2314 writeStringToParcel(p, p_cur[i].ifname);
2315 writeStringToParcel(p, p_cur[i].addresses);
2316 writeStringToParcel(p, p_cur[i].dnses);
2317 writeStringToParcel(p, p_cur[i].gateways);
2318 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2319 p_cur[i].status,
2320 p_cur[i].suggestedRetryTime,
2321 p_cur[i].cid,
2322 (p_cur[i].active==0)?"down":"up",
2323 (char*)p_cur[i].type,
2324 (char*)p_cur[i].ifname,
2325 (char*)p_cur[i].addresses,
2326 (char*)p_cur[i].dnses,
2327 (char*)p_cur[i].gateways);
2328 }
2329 removeLastChar;
2330 closeResponse;
2331
2332 return 0;
2333}
2334
Wink Saville43808972011-01-13 17:39:51 -08002335static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2336{
Wink Saville43808972011-01-13 17:39:51 -08002337 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002338 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002339 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002340 } else {
2341 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002342 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002343 return RIL_ERRNO_INVALID_RESPONSE;
2344 }
2345
Etan Cohend3652192014-06-20 08:28:44 -07002346 // Support v6 or v9 with new rils
2347 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002348 RLOGD("responseDataCallList: v6");
Etan Cohend3652192014-06-20 08:28:44 -07002349 return responseDataCallListV6(p, response, responselen);
2350 }
2351
2352 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002353 RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002354 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002355 return RIL_ERRNO_INVALID_RESPONSE;
2356 }
2357
Amit Mahajan52500162014-07-29 17:36:48 -07002358 // Write version
2359 p.writeInt32(10);
2360
Etan Cohend3652192014-06-20 08:28:44 -07002361 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002362 p.writeInt32(num);
2363
Etan Cohend3652192014-06-20 08:28:44 -07002364 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002365 startResponse;
2366 int i;
2367 for (i = 0; i < num; i++) {
2368 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002369 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002370 p.writeInt32(p_cur[i].cid);
2371 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002372 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002373 writeStringToParcel(p, p_cur[i].ifname);
2374 writeStringToParcel(p, p_cur[i].addresses);
2375 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002376 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002377 writeStringToParcel(p, p_cur[i].pcscf);
2378 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002379 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002380 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002381 p_cur[i].cid,
2382 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002383 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002384 (char*)p_cur[i].ifname,
2385 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002386 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002387 (char*)p_cur[i].gateways,
2388 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002389 }
2390 removeLastChar;
2391 closeResponse;
2392 }
2393
2394 return 0;
2395}
2396
2397static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2398{
2399 if (s_callbacks.version < 5) {
2400 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2401 } else {
2402 return responseDataCallList(p, response, responselen);
2403 }
2404}
2405
Wink Savillef4c4d362009-04-02 01:37:03 -07002406static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002407 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002408 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002409 return RIL_ERRNO_INVALID_RESPONSE;
2410 }
2411
2412 // The java code reads -1 size as null byte array
2413 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002414 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002415 } else {
2416 p.writeInt32(responselen);
2417 p.write(response, responselen);
2418 }
2419
2420 return 0;
2421}
2422
2423
Wink Savillef4c4d362009-04-02 01:37:03 -07002424static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002425 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002426 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002427 return RIL_ERRNO_INVALID_RESPONSE;
2428 }
2429
2430 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002431 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002432 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2433 return RIL_ERRNO_INVALID_RESPONSE;
2434 }
2435
2436 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2437 p.writeInt32(p_cur->sw1);
2438 p.writeInt32(p_cur->sw2);
2439 writeStringToParcel(p, p_cur->simResponse);
2440
2441 startResponse;
2442 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2443 (char*)p_cur->simResponse);
2444 closeResponse;
2445
2446
2447 return 0;
2448}
2449
Wink Savillef4c4d362009-04-02 01:37:03 -07002450static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002451 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002452
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002453 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002454 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002455 return RIL_ERRNO_INVALID_RESPONSE;
2456 }
2457
2458 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002459 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002460 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2461 return RIL_ERRNO_INVALID_RESPONSE;
2462 }
2463
2464 /* number of call info's */
2465 num = responselen / sizeof(RIL_CallForwardInfo *);
2466 p.writeInt32(num);
2467
2468 startResponse;
2469 for (int i = 0 ; i < num ; i++) {
2470 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2471
2472 p.writeInt32(p_cur->status);
2473 p.writeInt32(p_cur->reason);
2474 p.writeInt32(p_cur->serviceClass);
2475 p.writeInt32(p_cur->toa);
2476 writeStringToParcel(p, p_cur->number);
2477 p.writeInt32(p_cur->timeSeconds);
2478 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2479 (p_cur->status==1)?"enable":"disable",
2480 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2481 (char*)p_cur->number,
2482 p_cur->timeSeconds);
2483 }
2484 removeLastChar;
2485 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002486
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002487 return 0;
2488}
2489
Wink Savillef4c4d362009-04-02 01:37:03 -07002490static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002491 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002492 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002493 return RIL_ERRNO_INVALID_RESPONSE;
2494 }
2495
2496 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002497 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002498 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2499 return RIL_ERRNO_INVALID_RESPONSE;
2500 }
2501
2502 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2503 p.writeInt32(p_cur->notificationType);
2504 p.writeInt32(p_cur->code);
2505 p.writeInt32(p_cur->index);
2506 p.writeInt32(p_cur->type);
2507 writeStringToParcel(p, p_cur->number);
2508
2509 startResponse;
2510 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2511 (p_cur->notificationType==0)?"mo":"mt",
2512 p_cur->code, p_cur->index, p_cur->type,
2513 (char*)p_cur->number);
2514 closeResponse;
2515
2516 return 0;
2517}
2518
Wink Saville3d54e742009-05-18 18:00:44 -07002519static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002520 int num;
2521
2522 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002523 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002524 return RIL_ERRNO_INVALID_RESPONSE;
2525 }
2526
2527 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002528 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002529 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2530 return RIL_ERRNO_INVALID_RESPONSE;
2531 }
2532
2533 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002534 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002535 num = responselen / sizeof(RIL_NeighboringCell *);
2536 p.writeInt32(num);
2537
2538 for (int i = 0 ; i < num ; i++) {
2539 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2540
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002541 p.writeInt32(p_cur->rssi);
2542 writeStringToParcel (p, p_cur->cid);
2543
2544 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2545 p_cur->cid, p_cur->rssi);
2546 }
2547 removeLastChar;
2548 closeResponse;
2549
2550 return 0;
2551}
2552
Wink Saville3d54e742009-05-18 18:00:44 -07002553/**
2554 * Marshall the signalInfoRecord into the parcel if it exists.
2555 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002556static void marshallSignalInfoRecord(Parcel &p,
2557 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002558 p.writeInt32(p_signalInfoRecord.isPresent);
2559 p.writeInt32(p_signalInfoRecord.signalType);
2560 p.writeInt32(p_signalInfoRecord.alertPitch);
2561 p.writeInt32(p_signalInfoRecord.signal);
2562}
2563
Wink Savillea592eeb2009-05-22 13:26:36 -07002564static int responseCdmaInformationRecords(Parcel &p,
2565 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002566 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002567 char* string8 = NULL;
2568 int buffer_lenght;
2569 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002570
2571 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002572 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002573 return RIL_ERRNO_INVALID_RESPONSE;
2574 }
2575
Wink Savillea592eeb2009-05-22 13:26:36 -07002576 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002577 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002578 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002579 return RIL_ERRNO_INVALID_RESPONSE;
2580 }
2581
Wink Savillea592eeb2009-05-22 13:26:36 -07002582 RIL_CDMA_InformationRecords *p_cur =
2583 (RIL_CDMA_InformationRecords *) response;
2584 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002585
2586 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002587 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002588
Wink Savillea592eeb2009-05-22 13:26:36 -07002589 for (int i = 0 ; i < num ; i++) {
2590 infoRec = &p_cur->infoRec[i];
2591 p.writeInt32(infoRec->name);
2592 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002593 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002594 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2595 if (infoRec->rec.display.alpha_len >
2596 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002597 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002598 expected not more than %d\n",
2599 (int)infoRec->rec.display.alpha_len,
2600 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2601 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002602 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002603 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2604 * sizeof(char) );
2605 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2606 string8[i] = infoRec->rec.display.alpha_buf[i];
2607 }
Wink Saville43808972011-01-13 17:39:51 -08002608 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002609 writeStringToParcel(p, (const char*)string8);
2610 free(string8);
2611 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002612 break;
2613 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002614 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002615 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002616 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002617 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002618 expected not more than %d\n",
2619 (int)infoRec->rec.number.len,
2620 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2621 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002622 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002623 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2624 * sizeof(char) );
2625 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2626 string8[i] = infoRec->rec.number.buf[i];
2627 }
Wink Saville43808972011-01-13 17:39:51 -08002628 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002629 writeStringToParcel(p, (const char*)string8);
2630 free(string8);
2631 string8 = NULL;
2632 p.writeInt32(infoRec->rec.number.number_type);
2633 p.writeInt32(infoRec->rec.number.number_plan);
2634 p.writeInt32(infoRec->rec.number.pi);
2635 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002636 break;
2637 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002638 p.writeInt32(infoRec->rec.signal.isPresent);
2639 p.writeInt32(infoRec->rec.signal.signalType);
2640 p.writeInt32(infoRec->rec.signal.alertPitch);
2641 p.writeInt32(infoRec->rec.signal.signal);
2642
2643 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2644 alertPitch=%X, signal=%X, ",
2645 printBuf, (int)infoRec->rec.signal.isPresent,
2646 (int)infoRec->rec.signal.signalType,
2647 (int)infoRec->rec.signal.alertPitch,
2648 (int)infoRec->rec.signal.signal);
2649 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002650 break;
2651 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002652 if (infoRec->rec.redir.redirectingNumber.len >
2653 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002654 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002655 expected not more than %d\n",
2656 (int)infoRec->rec.redir.redirectingNumber.len,
2657 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2658 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002659 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002660 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2661 .len + 1) * sizeof(char) );
2662 for (int i = 0;
2663 i < infoRec->rec.redir.redirectingNumber.len;
2664 i++) {
2665 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2666 }
Wink Saville43808972011-01-13 17:39:51 -08002667 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002668 writeStringToParcel(p, (const char*)string8);
2669 free(string8);
2670 string8 = NULL;
2671 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2672 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2673 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2674 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2675 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002676 break;
2677 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002678 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2679 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2680 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2681 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2682
2683 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2684 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2685 lineCtrlPowerDenial=%d, ", printBuf,
2686 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2687 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2688 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2689 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2690 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002691 break;
2692 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002693 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002694
Wink Savillea592eeb2009-05-22 13:26:36 -07002695 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2696 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002697 break;
2698 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002699 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2700 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2701
2702 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2703 infoRec->rec.audioCtrl.upLink,
2704 infoRec->rec.audioCtrl.downLink);
2705 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002706 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002707 case RIL_CDMA_T53_RELEASE_INFO_REC:
2708 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002709 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002710 return RIL_ERRNO_INVALID_RESPONSE;
2711 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002712 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002713 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002714 }
2715 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002716 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002717
Wink Savillea592eeb2009-05-22 13:26:36 -07002718 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002719}
2720
Wink Savillea592eeb2009-05-22 13:26:36 -07002721static int responseRilSignalStrength(Parcel &p,
2722 void *response, size_t responselen) {
2723 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002724 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002725 return RIL_ERRNO_INVALID_RESPONSE;
2726 }
2727
Wink Savillec0114b32011-02-18 10:14:07 -08002728 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002729 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002730
Wink Saville3d54e742009-05-18 18:00:44 -07002731 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2732 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2733 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2734 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2735 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2736 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2737 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002738 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002739 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002740 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002741 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002742 if (s_callbacks.version <= 6) {
2743 // signalStrength: -1 -> 99
2744 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2745 p_cur->LTE_SignalStrength.signalStrength = 99;
2746 }
2747 // rsrp: -1 -> INT_MAX all other negative value to positive.
2748 // So remap here
2749 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2750 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2751 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2752 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2753 }
2754 // rsrq: -1 -> INT_MAX
2755 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2756 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2757 }
2758 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002759
Wink Saville18e4ab12013-04-07 17:31:04 -07002760 // cqi: -1 -> INT_MAX
2761 if (p_cur->LTE_SignalStrength.cqi == -1) {
2762 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2763 }
2764 }
2765 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002766 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2767 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2768 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2769 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002770 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2771 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2772 } else {
2773 p.writeInt32(INT_MAX);
2774 }
Wink Savillec0114b32011-02-18 10:14:07 -08002775 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002776 p.writeInt32(99);
2777 p.writeInt32(INT_MAX);
2778 p.writeInt32(INT_MAX);
2779 p.writeInt32(INT_MAX);
2780 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002781 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002782 }
johnwangfdf825f2009-05-22 15:50:34 -07002783
2784 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002785 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002786 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2787 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2788 EVDO_SS.signalNoiseRatio=%d,\
2789 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002790 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002791 printBuf,
2792 p_cur->GW_SignalStrength.signalStrength,
2793 p_cur->GW_SignalStrength.bitErrorRate,
2794 p_cur->CDMA_SignalStrength.dbm,
2795 p_cur->CDMA_SignalStrength.ecio,
2796 p_cur->EVDO_SignalStrength.dbm,
2797 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002798 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2799 p_cur->LTE_SignalStrength.signalStrength,
2800 p_cur->LTE_SignalStrength.rsrp,
2801 p_cur->LTE_SignalStrength.rsrq,
2802 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002803 p_cur->LTE_SignalStrength.cqi,
2804 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002805 closeResponse;
2806
Wink Saville3d54e742009-05-18 18:00:44 -07002807 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002808 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002809 return RIL_ERRNO_INVALID_RESPONSE;
2810 }
2811
Wink Saville3d54e742009-05-18 18:00:44 -07002812 return 0;
2813}
2814
2815static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2816 if ((response == NULL) || (responselen == 0)) {
2817 return responseVoid(p, response, responselen);
2818 } else {
2819 return responseCdmaSignalInfoRecord(p, response, responselen);
2820 }
2821}
2822
2823static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2824 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002825 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002826 return RIL_ERRNO_INVALID_RESPONSE;
2827 }
2828
2829 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002830 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002831 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2832 return RIL_ERRNO_INVALID_RESPONSE;
2833 }
2834
2835 startResponse;
2836
2837 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2838 marshallSignalInfoRecord(p, *p_cur);
2839
2840 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2841 signal=%d]",
2842 printBuf,
2843 p_cur->isPresent,
2844 p_cur->signalType,
2845 p_cur->alertPitch,
2846 p_cur->signal);
2847
2848 closeResponse;
2849 return 0;
2850}
2851
Wink Savillea592eeb2009-05-22 13:26:36 -07002852static int responseCdmaCallWaiting(Parcel &p, void *response,
2853 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002854 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002855 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002856 return RIL_ERRNO_INVALID_RESPONSE;
2857 }
2858
Wink Savillec0114b32011-02-18 10:14:07 -08002859 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002860 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002861 }
2862
2863 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2864
2865 writeStringToParcel(p, p_cur->number);
2866 p.writeInt32(p_cur->numberPresentation);
2867 writeStringToParcel(p, p_cur->name);
2868 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2869
2870 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2871 p.writeInt32(p_cur->number_type);
2872 p.writeInt32(p_cur->number_plan);
2873 } else {
2874 p.writeInt32(0);
2875 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002876 }
2877
2878 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002879 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2880 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002881 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002882 printBuf,
2883 p_cur->number,
2884 p_cur->numberPresentation,
2885 p_cur->name,
2886 p_cur->signalInfoRecord.isPresent,
2887 p_cur->signalInfoRecord.signalType,
2888 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002889 p_cur->signalInfoRecord.signal,
2890 p_cur->number_type,
2891 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002892 closeResponse;
2893
2894 return 0;
2895}
2896
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002897static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2898 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002899 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002900 return RIL_ERRNO_INVALID_RESPONSE;
2901 }
2902
2903 startResponse;
2904 if (s_callbacks.version == 7) {
2905 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2906 p.writeInt32(p_cur->result);
2907 p.writeInt32(p_cur->ef_id);
2908 writeStringToParcel(p, p_cur->aid);
2909
2910 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2911 printBuf,
2912 p_cur->result,
2913 p_cur->ef_id,
2914 p_cur->aid);
2915 } else {
2916 int *p_cur = ((int *) response);
2917 p.writeInt32(p_cur[0]);
2918 p.writeInt32(p_cur[1]);
2919 writeStringToParcel(p, NULL);
2920
2921 appendPrintBuf("%sresult=%d, ef_id=%d",
2922 printBuf,
2923 p_cur[0],
2924 p_cur[1]);
2925 }
2926 closeResponse;
2927
2928 return 0;
2929}
2930
Wink Saville8a9e0212013-04-09 12:11:38 -07002931static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2932{
2933 if (response == NULL && responselen != 0) {
2934 RLOGE("invalid response: NULL");
2935 return RIL_ERRNO_INVALID_RESPONSE;
2936 }
2937
2938 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002939 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07002940 (int)responselen, (int)sizeof(RIL_CellInfo));
2941 return RIL_ERRNO_INVALID_RESPONSE;
2942 }
2943
2944 int num = responselen / sizeof(RIL_CellInfo);
2945 p.writeInt32(num);
2946
2947 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2948 startResponse;
2949 int i;
2950 for (i = 0; i < num; i++) {
2951 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2952 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2953 p.writeInt32((int)p_cur->cellInfoType);
2954 p.writeInt32(p_cur->registered);
2955 p.writeInt32(p_cur->timeStampType);
2956 p.writeInt64(p_cur->timeStamp);
2957 switch(p_cur->cellInfoType) {
2958 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07002959 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002960 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2961 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2962 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07002963 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2964 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002965 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2966 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2967
2968 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2969 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2970 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2971 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07002972 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2973 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2974 break;
2975 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07002976 case RIL_CELL_INFO_TYPE_WCDMA: {
2977 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2978 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2979 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2980 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2981 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2982 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2983 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2984 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2985 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2986
2987 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2988 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2989 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2990 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2991 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2992 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2993 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2994 break;
2995 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002996 case RIL_CELL_INFO_TYPE_CDMA: {
2997 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2998 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2999 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3000 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3001 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3002 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3003
3004 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3005 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3006 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3007 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3008 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3009
3010 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3011 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3012 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3013 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3014 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3015 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3016
3017 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3018 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3019 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3020 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3021 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3022 break;
3023 }
3024 case RIL_CELL_INFO_TYPE_LTE: {
3025 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3026 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3027 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3028 p_cur->CellInfo.lte.cellIdentityLte.ci,
3029 p_cur->CellInfo.lte.cellIdentityLte.pci,
3030 p_cur->CellInfo.lte.cellIdentityLte.tac);
3031
3032 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3033 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3034 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3035 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3036 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3037
3038 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3039 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3040 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3041 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3042 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3043 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3044 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3045 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3046 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3047 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3048 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3049 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3050 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3051 break;
3052 }
Etan Cohend3652192014-06-20 08:28:44 -07003053 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3054 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3055 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3056 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3057 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3058 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3059 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3060 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3061 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3062
3063 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3064 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3065 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3066 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3067 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3068 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3069 break;
3070 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003071 }
3072 p_cur += 1;
3073 }
3074 removeLastChar;
3075 closeResponse;
3076
3077 return 0;
3078}
3079
Etan Cohend3652192014-06-20 08:28:44 -07003080static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3081{
3082 if (response == NULL && responselen != 0) {
3083 RLOGE("invalid response: NULL");
3084 return RIL_ERRNO_INVALID_RESPONSE;
3085 }
3086
3087 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003088 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003089 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3090 return RIL_ERRNO_INVALID_RESPONSE;
3091 }
3092
3093 int num = responselen / sizeof(RIL_HardwareConfig);
3094 int i;
3095 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3096
3097 p.writeInt32(num);
3098
3099 startResponse;
3100 for (i = 0; i < num; i++) {
3101 switch (p_cur[i].type) {
3102 case RIL_HARDWARE_CONFIG_MODEM: {
3103 writeStringToParcel(p, p_cur[i].uuid);
3104 p.writeInt32((int)p_cur[i].state);
3105 p.writeInt32(p_cur[i].cfg.modem.rat);
3106 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3107 p.writeInt32(p_cur[i].cfg.modem.maxData);
3108 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3109
3110 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3111 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3112 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3113 break;
3114 }
3115 case RIL_HARDWARE_CONFIG_SIM: {
3116 writeStringToParcel(p, p_cur[i].uuid);
3117 p.writeInt32((int)p_cur[i].state);
3118 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3119
3120 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3121 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3122 break;
3123 }
3124 }
3125 }
3126 removeLastChar;
3127 closeResponse;
3128 return 0;
3129}
3130
Wink Saville3d54e742009-05-18 18:00:44 -07003131static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003132 int ret;
3133 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3134 /* trigger event loop to wakeup. No reason to do this,
3135 * if we're in the event loop thread */
3136 do {
3137 ret = write (s_fdWakeupWrite, " ", 1);
3138 } while (ret < 0 && errno == EINTR);
3139 }
3140}
3141
Wink Saville3d54e742009-05-18 18:00:44 -07003142static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003143 ril_event_add(ev);
3144 triggerEvLoop();
3145}
3146
Wink Savillefd729372011-02-22 16:19:39 -08003147static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3148 p.writeInt32(num_apps);
3149 startResponse;
3150 for (int i = 0; i < num_apps; i++) {
3151 p.writeInt32(appStatus[i].app_type);
3152 p.writeInt32(appStatus[i].app_state);
3153 p.writeInt32(appStatus[i].perso_substate);
3154 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3155 writeStringToParcel(p, (const char*)
3156 (appStatus[i].app_label_ptr));
3157 p.writeInt32(appStatus[i].pin1_replaced);
3158 p.writeInt32(appStatus[i].pin1);
3159 p.writeInt32(appStatus[i].pin2);
3160 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3161 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3162 printBuf,
3163 appStatus[i].app_type,
3164 appStatus[i].app_state,
3165 appStatus[i].perso_substate,
3166 appStatus[i].aid_ptr,
3167 appStatus[i].app_label_ptr,
3168 appStatus[i].pin1_replaced,
3169 appStatus[i].pin1,
3170 appStatus[i].pin2);
3171 }
3172 closeResponse;
3173}
3174
Wink Savillef4c4d362009-04-02 01:37:03 -07003175static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3176 int i;
3177
3178 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003179 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003180 return RIL_ERRNO_INVALID_RESPONSE;
3181 }
3182
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003183 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003184 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003185
Wink Savillefd729372011-02-22 16:19:39 -08003186 p.writeInt32(p_cur->card_state);
3187 p.writeInt32(p_cur->universal_pin_state);
3188 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3189 p.writeInt32(p_cur->cdma_subscription_app_index);
3190 p.writeInt32(p_cur->ims_subscription_app_index);
3191
3192 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003193 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003194 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3195
3196 p.writeInt32(p_cur->card_state);
3197 p.writeInt32(p_cur->universal_pin_state);
3198 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3199 p.writeInt32(p_cur->cdma_subscription_app_index);
3200 p.writeInt32(-1);
3201
3202 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003203 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003204 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003205 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003206 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003207
3208 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003209}
Wink Savillef4c4d362009-04-02 01:37:03 -07003210
Wink Savillea592eeb2009-05-22 13:26:36 -07003211static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3212 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003213 p.writeInt32(num);
3214
Wink Savillef4c4d362009-04-02 01:37:03 -07003215 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003216 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3217 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3218 for (int i = 0; i < num; i++) {
3219 p.writeInt32(p_cur[i]->fromServiceId);
3220 p.writeInt32(p_cur[i]->toServiceId);
3221 p.writeInt32(p_cur[i]->fromCodeScheme);
3222 p.writeInt32(p_cur[i]->toCodeScheme);
3223 p.writeInt32(p_cur[i]->selected);
3224
3225 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3226 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3227 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3228 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3229 p_cur[i]->selected);
3230 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003231 closeResponse;
3232
3233 return 0;
3234}
3235
Wink Savillea592eeb2009-05-22 13:26:36 -07003236static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3237 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3238 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003239
Wink Savillea592eeb2009-05-22 13:26:36 -07003240 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3241 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003242
3243 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003244 for (int i = 0 ; i < num ; i++ ) {
3245 p.writeInt32(p_cur[i]->service_category);
3246 p.writeInt32(p_cur[i]->language);
3247 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003248
Wink Savillea592eeb2009-05-22 13:26:36 -07003249 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3250 selected =%d], ",
3251 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3252 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003253 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003254 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003255
Wink Savillef4c4d362009-04-02 01:37:03 -07003256 return 0;
3257}
3258
3259static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3260 int num;
3261 int digitCount;
3262 int digitLimit;
3263 uint8_t uct;
3264 void* dest;
3265
Wink Saville8eb2a122012-11-19 16:05:13 -08003266 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003267
Wink Savillef4c4d362009-04-02 01:37:03 -07003268 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003269 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003270 return RIL_ERRNO_INVALID_RESPONSE;
3271 }
3272
Wink Savillef5903df2009-04-24 11:54:14 -07003273 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003274 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003275 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003276 return RIL_ERRNO_INVALID_RESPONSE;
3277 }
3278
3279 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3280 p.writeInt32(p_cur->uTeleserviceID);
3281 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3282 p.writeInt32(p_cur->uServicecategory);
3283 p.writeInt32(p_cur->sAddress.digit_mode);
3284 p.writeInt32(p_cur->sAddress.number_mode);
3285 p.writeInt32(p_cur->sAddress.number_type);
3286 p.writeInt32(p_cur->sAddress.number_plan);
3287 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3288 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3289 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3290 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3291 }
3292
3293 p.writeInt32(p_cur->sSubAddress.subaddressType);
3294 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3295 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3296 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3297 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3298 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3299 }
3300
3301 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3302 p.writeInt32(p_cur->uBearerDataLen);
3303 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3304 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3305 }
3306
3307 startResponse;
3308 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003309 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003310 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3311 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3312 closeResponse;
3313
3314 return 0;
3315}
3316
Wink Savillec29360a2014-07-13 05:17:28 -07003317static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3318{
3319 int num = responselen / sizeof(RIL_DcRtInfo);
3320 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003321 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003322 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3323 return RIL_ERRNO_INVALID_RESPONSE;
3324 }
3325
3326 startResponse;
3327 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3328 p.writeInt64(pDcRtInfo->time);
3329 p.writeInt32(pDcRtInfo->powerState);
3330 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3331 pDcRtInfo->time,
3332 pDcRtInfo->powerState);
3333 closeResponse;
3334
3335 return 0;
3336}
3337
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003338/**
3339 * A write on the wakeup fd is done just to pop us out of select()
3340 * We empty the buffer here and then ril_event will reset the timers on the
3341 * way back down
3342 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003343static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003344 char buff[16];
3345 int ret;
3346
Wink Saville8eb2a122012-11-19 16:05:13 -08003347 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003348
3349 /* empty our wakeup socket out */
3350 do {
3351 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003352 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003353}
3354
Etan Cohend3652192014-06-20 08:28:44 -07003355static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003356 int ret;
3357 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003358 /* Hook for current context
3359 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3360 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3361 /* pendingRequestsHook refer to &s_pendingRequests */
3362 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003363
Etan Cohend3652192014-06-20 08:28:44 -07003364#if (SIM_COUNT >= 2)
3365 if (socket_id == RIL_SOCKET_2) {
3366 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3367 pendingRequestsHook = &s_pendingRequests_socket2;
3368 }
3369#if (SIM_COUNT >= 3)
3370 else if (socket_id == RIL_SOCKET_3) {
3371 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3372 pendingRequestsHook = &s_pendingRequests_socket3;
3373 }
3374#endif
3375#if (SIM_COUNT >= 4)
3376 else if (socket_id == RIL_SOCKET_4) {
3377 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3378 pendingRequestsHook = &s_pendingRequests_socket4;
3379 }
3380#endif
3381#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003382 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003383 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003384 assert (ret == 0);
3385
Etan Cohend3652192014-06-20 08:28:44 -07003386 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003387
Etan Cohend3652192014-06-20 08:28:44 -07003388 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003389 ; p_cur != NULL
3390 ; p_cur = p_cur->p_next
3391 ) {
3392 p_cur->cancelled = 1;
3393 }
3394
Etan Cohend3652192014-06-20 08:28:44 -07003395 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003396 assert (ret == 0);
3397}
3398
Wink Savillef4c4d362009-04-02 01:37:03 -07003399static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003400 RecordStream *p_rs;
3401 void *p_record;
3402 size_t recordlen;
3403 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003404 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003405
Etan Cohend3652192014-06-20 08:28:44 -07003406 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003407
Etan Cohend3652192014-06-20 08:28:44 -07003408 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003409
3410 for (;;) {
3411 /* loop until EAGAIN/EINTR, end of stream, or other error */
3412 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3413
3414 if (ret == 0 && p_record == NULL) {
3415 /* end-of-stream */
3416 break;
3417 } else if (ret < 0) {
3418 break;
3419 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003420 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003421 }
3422 }
3423
3424 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3425 /* fatal error or end-of-stream */
3426 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003427 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003428 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003429 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003430 }
Wink Saville7f856802009-06-09 10:23:37 -07003431
Etan Cohend3652192014-06-20 08:28:44 -07003432 close(fd);
3433 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003434
Etan Cohend3652192014-06-20 08:28:44 -07003435 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003436
3437 record_stream_free(p_rs);
3438
3439 /* start listening for new connections again */
3440 rilEventAddWakeup(&s_listen_event);
3441
Etan Cohend3652192014-06-20 08:28:44 -07003442 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003443 }
3444}
3445
3446
Etan Cohend3652192014-06-20 08:28:44 -07003447static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003448 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003449 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003450 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3451 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003452
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003453 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003454 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3455 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003456
3457 // Send last NITZ time data, in case it was missed
3458 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003459 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003460
3461 free(s_lastNITZTimeData);
3462 s_lastNITZTimeData = NULL;
3463 }
3464
3465 // Get version string
3466 if (s_callbacks.getVersion != NULL) {
3467 const char *version;
3468 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003469 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003470
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003471 property_set(PROPERTY_RIL_IMPL, version);
3472 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003473 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003474 property_set(PROPERTY_RIL_IMPL, "unavailable");
3475 }
3476
3477}
3478
Wink Savillef4c4d362009-04-02 01:37:03 -07003479static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003480 int ret;
3481 int err;
3482 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003483 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003484 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003485 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003486
3487 struct sockaddr_un peeraddr;
3488 socklen_t socklen = sizeof (peeraddr);
3489
3490 struct ucred creds;
3491 socklen_t szCreds = sizeof(creds);
3492
3493 struct passwd *pwd = NULL;
3494
Etan Cohend3652192014-06-20 08:28:44 -07003495 assert (*p_info->fdCommand < 0);
3496 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003497
Etan Cohend3652192014-06-20 08:28:44 -07003498 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003499
Etan Cohend3652192014-06-20 08:28:44 -07003500 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003501 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003502 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003503 rilEventAddWakeup(p_info->listen_event);
3504 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003505 }
3506
3507 /* check the credential of the other side and only accept socket from
3508 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003509 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003510 errno = 0;
3511 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003512
Etan Cohend3652192014-06-20 08:28:44 -07003513 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003514
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003515 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003516 errno = 0;
3517 pwd = getpwuid(creds.uid);
3518 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003519 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003520 is_phone_socket = 1;
3521 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003522 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003523 }
3524 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003525 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003526 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003527 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003528 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003529 }
3530
Etan Cohend3652192014-06-20 08:28:44 -07003531 if (!is_phone_socket) {
3532 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003533
Etan Cohend3652192014-06-20 08:28:44 -07003534 close(fdCommand);
3535 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003536
Etan Cohend3652192014-06-20 08:28:44 -07003537 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003538
3539 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003540 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003541
3542 return;
3543 }
3544
Etan Cohend3652192014-06-20 08:28:44 -07003545 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003546
3547 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003548 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003549 }
3550
Etan Cohend3652192014-06-20 08:28:44 -07003551 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003552
Etan Cohend3652192014-06-20 08:28:44 -07003553 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003554
Etan Cohend3652192014-06-20 08:28:44 -07003555 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003556
Etan Cohend3652192014-06-20 08:28:44 -07003557 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003558
Etan Cohend3652192014-06-20 08:28:44 -07003559 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3560 p_info->processCommandsCallback, p_info);
3561
3562 rilEventAddWakeup (p_info->commands_event);
3563
3564 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003565}
3566
3567static void freeDebugCallbackArgs(int number, char **args) {
3568 for (int i = 0; i < number; i++) {
3569 if (args[i] != NULL) {
3570 free(args[i]);
3571 }
3572 }
3573 free(args);
3574}
3575
Wink Savillef4c4d362009-04-02 01:37:03 -07003576static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003577 int acceptFD, option;
3578 struct sockaddr_un peeraddr;
3579 socklen_t socklen = sizeof (peeraddr);
3580 int data;
3581 unsigned int qxdm_data[6];
3582 const char *deactData[1] = {"1"};
3583 char *actData[1];
3584 RIL_Dial dialData;
3585 int hangupData[1] = {1};
3586 int number;
3587 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003588 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3589 int sim_id = 0;
3590
3591 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003592
3593 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3594
3595 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003596 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003597 return;
3598 }
3599
3600 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003601 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003602 return;
3603 }
3604 args = (char **) malloc(sizeof(char*) * number);
3605
3606 for (int i = 0; i < number; i++) {
3607 int len;
3608 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003609 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003610 freeDebugCallbackArgs(i, args);
3611 return;
3612 }
3613 // +1 for null-term
3614 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003615 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003616 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003617 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003618 freeDebugCallbackArgs(i, args);
3619 return;
3620 }
3621 char * buf = args[i];
3622 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003623 if ((i+1) == number) {
3624 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3625 sim_id = atoi(args[i]);
3626 switch (sim_id) {
3627 case 0:
3628 socket_id = RIL_SOCKET_1;
3629 break;
3630 #if (SIM_COUNT >= 2)
3631 case 1:
3632 socket_id = RIL_SOCKET_2;
3633 break;
3634 #endif
3635 #if (SIM_COUNT >= 3)
3636 case 2:
3637 socket_id = RIL_SOCKET_3;
3638 break;
3639 #endif
3640 #if (SIM_COUNT >= 4)
3641 case 3:
3642 socket_id = RIL_SOCKET_4;
3643 break;
3644 #endif
3645 default:
3646 socket_id = RIL_SOCKET_1;
3647 break;
3648 }
3649 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003650 }
3651
3652 switch (atoi(args[0])) {
3653 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003654 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003655 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003656 break;
3657 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003658 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003659 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003660 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003661 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003662 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3663 close(s_ril_param_socket.fdCommand);
3664 s_ril_param_socket.fdCommand = -1;
3665 }
3666 #if (SIM_COUNT == 2)
3667 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3668 close(s_ril_param_socket2.fdCommand);
3669 s_ril_param_socket2.fdCommand = -1;
3670 }
3671 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672 break;
3673 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003674 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003675 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003676 break;
3677 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003678 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003679 qxdm_data[0] = 65536; // head.func_tag
3680 qxdm_data[1] = 16; // head.len
3681 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3682 qxdm_data[3] = 32; // log_file_size: 32megabytes
3683 qxdm_data[4] = 0; // log_mask
3684 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003685 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003686 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003687 break;
3688 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003689 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003690 qxdm_data[0] = 65536;
3691 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003692 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003693 qxdm_data[3] = 32;
3694 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003695 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003696 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003697 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003698 break;
3699 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003700 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003701 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003702 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003703 sleep(2);
3704 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003705 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003706 break;
3707 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003708 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003709 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003710 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003711 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003712 break;
3713 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003714 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003715 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003716 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003717 break;
3718 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003719 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003720 dialData.clir = 0;
3721 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003722 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003723 break;
3724 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003725 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003726 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727 break;
3728 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003729 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003730 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003731 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003732 break;
3733 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003734 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003735 break;
3736 }
3737 freeDebugCallbackArgs(number, args);
3738 close(acceptFD);
3739}
3740
3741
Wink Savillef4c4d362009-04-02 01:37:03 -07003742static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003743 UserCallbackInfo *p_info;
3744
3745 p_info = (UserCallbackInfo *)param;
3746
3747 p_info->p_callback(p_info->userParam);
3748
3749
3750 // FIXME generalize this...there should be a cancel mechanism
3751 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3752 s_last_wake_timeout_info = NULL;
3753 }
3754
3755 free(p_info);
3756}
3757
3758
3759static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003760eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003761 int ret;
3762 int filedes[2];
3763
3764 ril_event_init();
3765
3766 pthread_mutex_lock(&s_startupMutex);
3767
3768 s_started = 1;
3769 pthread_cond_broadcast(&s_startupCond);
3770
3771 pthread_mutex_unlock(&s_startupMutex);
3772
3773 ret = pipe(filedes);
3774
3775 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003776 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003777 return NULL;
3778 }
3779
3780 s_fdWakeupRead = filedes[0];
3781 s_fdWakeupWrite = filedes[1];
3782
3783 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3784
3785 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3786 processWakeupCallback, NULL);
3787
3788 rilEventAddWakeup (&s_wakeupfd_event);
3789
3790 // Only returns on error
3791 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003792 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003793 // kill self to restart on error
3794 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003795
3796 return NULL;
3797}
3798
Wink Saville7f856802009-06-09 10:23:37 -07003799extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003800RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003801 /* spin up eventLoop thread and wait for it to get started */
3802 s_started = 0;
3803 pthread_mutex_lock(&s_startupMutex);
3804
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003805 pthread_attr_t attr;
3806 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003807 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003808
Elliott Hughesfd81e712014-01-06 12:46:02 -08003809 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3810 if (result != 0) {
3811 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003812 goto done;
3813 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003814
3815 while (s_started == 0) {
3816 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3817 }
3818
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003819done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003820 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003821}
3822
3823// Used for testing purpose only.
3824extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3825 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3826}
3827
Etan Cohend3652192014-06-20 08:28:44 -07003828static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3829 int fdListen = -1;
3830 int ret;
3831 char socket_name[10];
3832
3833 memset(socket_name, 0, sizeof(char)*10);
3834
3835 switch(socket_id) {
3836 case RIL_SOCKET_1:
3837 strncpy(socket_name, RIL_getRilSocketName(), 9);
3838 break;
3839 #if (SIM_COUNT >= 2)
3840 case RIL_SOCKET_2:
3841 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3842 break;
3843 #endif
3844 #if (SIM_COUNT >= 3)
3845 case RIL_SOCKET_3:
3846 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3847 break;
3848 #endif
3849 #if (SIM_COUNT >= 4)
3850 case RIL_SOCKET_4:
3851 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3852 break;
3853 #endif
3854 default:
3855 RLOGE("Socket id is wrong!!");
3856 return;
3857 }
3858
3859 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3860
3861 fdListen = android_get_control_socket(socket_name);
3862 if (fdListen < 0) {
3863 RLOGE("Failed to get socket %s", socket_name);
3864 exit(-1);
3865 }
3866
3867 ret = listen(fdListen, 4);
3868
3869 if (ret < 0) {
3870 RLOGE("Failed to listen on control socket '%d': %s",
3871 fdListen, strerror(errno));
3872 exit(-1);
3873 }
3874 socket_listen_p->fdListen = fdListen;
3875
3876 /* note: non-persistent so we can accept only one connection at a time */
3877 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3878 listenCallback, socket_listen_p);
3879
3880 rilEventAddWakeup (socket_listen_p->listen_event);
3881}
3882
Wink Saville7f856802009-06-09 10:23:37 -07003883extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003884RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003885 int ret;
3886 int flags;
3887
Etan Cohend3652192014-06-20 08:28:44 -07003888 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3889
Wink Saville43808972011-01-13 17:39:51 -08003890 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003891 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003892 return;
3893 }
Wink Saville43808972011-01-13 17:39:51 -08003894 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003895 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003896 callbacks->version, RIL_VERSION_MIN);
3897 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07003898 }
Wink Saville43808972011-01-13 17:39:51 -08003899 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003900 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003901 callbacks->version, RIL_VERSION);
3902 return;
3903 }
Wink Saville8eb2a122012-11-19 16:05:13 -08003904 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003905
3906 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003907 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003908 "Subsequent call ignored");
3909 return;
3910 }
3911
3912 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3913
Etan Cohend3652192014-06-20 08:28:44 -07003914 /* Initialize socket1 parameters */
3915 s_ril_param_socket = {
3916 RIL_SOCKET_1, /* socket_id */
3917 -1, /* fdListen */
3918 -1, /* fdCommand */
3919 PHONE_PROCESS, /* processName */
3920 &s_commands_event, /* commands_event */
3921 &s_listen_event, /* listen_event */
3922 processCommandsCallback, /* processCommandsCallback */
3923 NULL /* p_rs */
3924 };
3925
3926#if (SIM_COUNT >= 2)
3927 s_ril_param_socket2 = {
3928 RIL_SOCKET_2, /* socket_id */
3929 -1, /* fdListen */
3930 -1, /* fdCommand */
3931 PHONE_PROCESS, /* processName */
3932 &s_commands_event_socket2, /* commands_event */
3933 &s_listen_event_socket2, /* listen_event */
3934 processCommandsCallback, /* processCommandsCallback */
3935 NULL /* p_rs */
3936 };
3937#endif
3938
3939#if (SIM_COUNT >= 3)
3940 s_ril_param_socket3 = {
3941 RIL_SOCKET_3, /* socket_id */
3942 -1, /* fdListen */
3943 -1, /* fdCommand */
3944 PHONE_PROCESS, /* processName */
3945 &s_commands_event_socket3, /* commands_event */
3946 &s_listen_event_socket3, /* listen_event */
3947 processCommandsCallback, /* processCommandsCallback */
3948 NULL /* p_rs */
3949 };
3950#endif
3951
3952#if (SIM_COUNT >= 4)
3953 s_ril_param_socket4 = {
3954 RIL_SOCKET_4, /* socket_id */
3955 -1, /* fdListen */
3956 -1, /* fdCommand */
3957 PHONE_PROCESS, /* processName */
3958 &s_commands_event_socket4, /* commands_event */
3959 &s_listen_event_socket4, /* listen_event */
3960 processCommandsCallback, /* processCommandsCallback */
3961 NULL /* p_rs */
3962 };
3963#endif
3964
3965
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003966 s_registerCalled = 1;
3967
Etan Cohend3652192014-06-20 08:28:44 -07003968 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003969 // Little self-check
3970
Wink Savillef4c4d362009-04-02 01:37:03 -07003971 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003972 assert(i == s_commands[i].requestNumber);
3973 }
3974
Wink Savillef4c4d362009-04-02 01:37:03 -07003975 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07003976 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003977 == s_unsolResponses[i].requestNumber);
3978 }
3979
3980 // New rild impl calls RIL_startEventLoop() first
3981 // old standalone impl wants it here.
3982
3983 if (s_started == 0) {
3984 RIL_startEventLoop();
3985 }
3986
Etan Cohend3652192014-06-20 08:28:44 -07003987 // start listen socket1
3988 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003989
Etan Cohend3652192014-06-20 08:28:44 -07003990#if (SIM_COUNT >= 2)
3991 // start listen socket2
3992 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
3993#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003994
Etan Cohend3652192014-06-20 08:28:44 -07003995#if (SIM_COUNT >= 3)
3996 // start listen socket3
3997 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
3998#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003999
Etan Cohend3652192014-06-20 08:28:44 -07004000#if (SIM_COUNT >= 4)
4001 // start listen socket4
4002 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4003#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004004
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004005
4006#if 1
4007 // start debug interface socket
4008
Etan Cohend3652192014-06-20 08:28:44 -07004009 char *inst = NULL;
4010 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4011 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4012 }
4013
4014 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4015 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004016 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004017 }
4018
4019 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004020 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004021 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004022 exit(-1);
4023 }
4024
4025 ret = listen(s_fdDebug, 4);
4026
4027 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004028 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004029 s_fdDebug, strerror(errno));
4030 exit(-1);
4031 }
4032
4033 ril_event_set (&s_debug_event, s_fdDebug, true,
4034 debugCallback, NULL);
4035
4036 rilEventAddWakeup (&s_debug_event);
4037#endif
4038
4039}
4040
4041static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004042checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004043 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004044 /* Hook for current context
4045 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4046 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4047 /* pendingRequestsHook refer to &s_pendingRequests */
4048 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004049
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004050 if (pRI == NULL) {
4051 return 0;
4052 }
4053
Etan Cohend3652192014-06-20 08:28:44 -07004054#if (SIM_COUNT >= 2)
4055 if (pRI->socket_id == RIL_SOCKET_2) {
4056 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4057 pendingRequestsHook = &s_pendingRequests_socket2;
4058 }
4059#if (SIM_COUNT >= 3)
4060 if (pRI->socket_id == RIL_SOCKET_3) {
4061 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4062 pendingRequestsHook = &s_pendingRequests_socket3;
4063 }
4064#endif
4065#if (SIM_COUNT >= 4)
4066 if (pRI->socket_id == RIL_SOCKET_4) {
4067 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4068 pendingRequestsHook = &s_pendingRequests_socket4;
4069 }
4070#endif
4071#endif
4072 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004073
Etan Cohend3652192014-06-20 08:28:44 -07004074 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004075 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076 ; ppCur = &((*ppCur)->p_next)
4077 ) {
4078 if (pRI == *ppCur) {
4079 ret = 1;
4080
4081 *ppCur = (*ppCur)->p_next;
4082 break;
4083 }
4084 }
4085
Etan Cohend3652192014-06-20 08:28:44 -07004086 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004087
4088 return ret;
4089}
4090
4091
4092extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004093RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004094 RequestInfo *pRI;
4095 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004096 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004097 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004098 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004099
4100 pRI = (RequestInfo *)t;
4101
Jayachandran C6c607592014-08-04 15:48:01 -07004102 if (!checkAndDequeueRequestInfo(pRI)) {
4103 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4104 return;
4105 }
4106
Etan Cohend3652192014-06-20 08:28:44 -07004107 socket_id = pRI->socket_id;
4108#if (SIM_COUNT >= 2)
4109 if (socket_id == RIL_SOCKET_2) {
4110 fd = s_ril_param_socket2.fdCommand;
4111 }
4112#if (SIM_COUNT >= 3)
4113 if (socket_id == RIL_SOCKET_3) {
4114 fd = s_ril_param_socket3.fdCommand;
4115 }
4116#endif
4117#if (SIM_COUNT >= 4)
4118 if (socket_id == RIL_SOCKET_4) {
4119 fd = s_ril_param_socket4.fdCommand;
4120 }
4121#endif
4122#endif
4123 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4124
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004125 if (pRI->local > 0) {
4126 // Locally issued command...void only!
4127 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004128 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004129
4130 goto done;
4131 }
4132
4133 appendPrintBuf("[%04d]< %s",
4134 pRI->token, requestToString(pRI->pCI->requestNumber));
4135
4136 if (pRI->cancelled == 0) {
4137 Parcel p;
4138
4139 p.writeInt32 (RESPONSE_SOLICITED);
4140 p.writeInt32 (pRI->token);
4141 errorOffset = p.dataPosition();
4142
4143 p.writeInt32 (e);
4144
johnwangb2a61842009-06-02 14:55:45 -07004145 if (response != NULL) {
4146 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004147 ret = pRI->pCI->responseFunction(p, response, responselen);
4148
4149 /* if an error occurred, rewind and mark it */
4150 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004151 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004152 p.setDataPosition(errorOffset);
4153 p.writeInt32 (ret);
4154 }
johnwangb2a61842009-06-02 14:55:45 -07004155 }
4156
4157 if (e != RIL_E_SUCCESS) {
4158 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004159 }
4160
Etan Cohend3652192014-06-20 08:28:44 -07004161 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004162 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004163 }
Etan Cohend3652192014-06-20 08:28:44 -07004164 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004165 }
4166
4167done:
4168 free(pRI);
4169}
4170
4171
4172static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004173grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004174 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4175}
4176
4177static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004178releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004179 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4180}
4181
4182/**
4183 * Timer callback to put us back to sleep before the default timeout
4184 */
4185static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004186wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004187 // We're using "param != NULL" as a cancellation mechanism
4188 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004189 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004190 }
4191}
4192
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004193static int
4194decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4195 switch (radioState) {
4196 case RADIO_STATE_SIM_NOT_READY:
4197 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4198 case RADIO_STATE_SIM_READY:
4199 return RADIO_TECH_UMTS;
4200
4201 case RADIO_STATE_RUIM_NOT_READY:
4202 case RADIO_STATE_RUIM_READY:
4203 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4204 case RADIO_STATE_NV_NOT_READY:
4205 case RADIO_STATE_NV_READY:
4206 return RADIO_TECH_1xRTT;
4207
4208 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004209 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004210 return -1;
4211 }
4212}
4213
4214static int
4215decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4216 switch (radioState) {
4217 case RADIO_STATE_SIM_NOT_READY:
4218 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4219 case RADIO_STATE_SIM_READY:
4220 case RADIO_STATE_RUIM_NOT_READY:
4221 case RADIO_STATE_RUIM_READY:
4222 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4223 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4224
4225 case RADIO_STATE_NV_NOT_READY:
4226 case RADIO_STATE_NV_READY:
4227 return CDMA_SUBSCRIPTION_SOURCE_NV;
4228
4229 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004230 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004231 return -1;
4232 }
4233}
4234
4235static int
4236decodeSimStatus (RIL_RadioState radioState) {
4237 switch (radioState) {
4238 case RADIO_STATE_SIM_NOT_READY:
4239 case RADIO_STATE_RUIM_NOT_READY:
4240 case RADIO_STATE_NV_NOT_READY:
4241 case RADIO_STATE_NV_READY:
4242 return -1;
4243 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4244 case RADIO_STATE_SIM_READY:
4245 case RADIO_STATE_RUIM_READY:
4246 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4247 return radioState;
4248 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004249 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004250 return -1;
4251 }
4252}
4253
4254static bool is3gpp2(int radioTech) {
4255 switch (radioTech) {
4256 case RADIO_TECH_IS95A:
4257 case RADIO_TECH_IS95B:
4258 case RADIO_TECH_1xRTT:
4259 case RADIO_TECH_EVDO_0:
4260 case RADIO_TECH_EVDO_A:
4261 case RADIO_TECH_EVDO_B:
4262 case RADIO_TECH_EHRPD:
4263 return true;
4264 default:
4265 return false;
4266 }
4267}
4268
4269/* If RIL sends SIM states or RUIM states, store the voice radio
4270 * technology and subscription source information so that they can be
4271 * returned when telephony framework requests them
4272 */
4273static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004274processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004275
4276 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4277 int newVoiceRadioTech;
4278 int newCdmaSubscriptionSource;
4279 int newSimStatus;
4280
4281 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4282 from Radio State and send change notifications if there has been a change */
4283 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4284 if(newVoiceRadioTech != voiceRadioTech) {
4285 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004286 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4287 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004288 }
4289 if(is3gpp2(newVoiceRadioTech)) {
4290 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4291 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4292 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004293 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4294 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004295 }
4296 }
4297 newSimStatus = decodeSimStatus(newRadioState);
4298 if(newSimStatus != simRuimStatus) {
4299 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004300 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004301 }
4302
4303 /* Send RADIO_ON to telephony */
4304 newRadioState = RADIO_STATE_ON;
4305 }
4306
4307 return newRadioState;
4308}
4309
Etan Cohend3652192014-06-20 08:28:44 -07004310
4311#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004312extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004313void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004314 size_t datalen, RIL_SOCKET_ID socket_id)
4315#else
4316extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004317void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004318 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004319#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004320{
4321 int unsolResponseIndex;
4322 int ret;
4323 int64_t timeReceived = 0;
4324 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004325 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004326 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4327
4328#if defined(ANDROID_MULTI_SIM)
4329 soc_id = socket_id;
4330#endif
4331
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004332
4333 if (s_registerCalled == 0) {
4334 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004335 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004336 return;
4337 }
Wink Saville7f856802009-06-09 10:23:37 -07004338
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004339 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4340
4341 if ((unsolResponseIndex < 0)
4342 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004343 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004344 return;
4345 }
4346
4347 // Grab a wake lock if needed for this reponse,
4348 // as we exit we'll either release it immediately
4349 // or set a timer to release it later.
4350 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4351 case WAKE_PARTIAL:
4352 grabPartialWakeLock();
4353 shouldScheduleTimeout = true;
4354 break;
4355
4356 case DONT_WAKE:
4357 default:
4358 // No wake lock is grabed so don't set timeout
4359 shouldScheduleTimeout = false;
4360 break;
4361 }
4362
4363 // Mark the time this was received, doing this
4364 // after grabing the wakelock incase getting
4365 // the elapsedRealTime might cause us to goto
4366 // sleep.
4367 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4368 timeReceived = elapsedRealtime();
4369 }
4370
4371 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4372
4373 Parcel p;
4374
4375 p.writeInt32 (RESPONSE_UNSOLICITED);
4376 p.writeInt32 (unsolResponse);
4377
4378 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004379 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 if (ret != 0) {
4381 // Problem with the response. Don't continue;
4382 goto error_exit;
4383 }
4384
4385 // some things get more payload
4386 switch(unsolResponse) {
4387 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004388 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004389 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004390 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004391 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004392 break;
4393
4394
4395 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4396 // Store the time that this was received so the
4397 // handler of this message can account for
4398 // the time it takes to arrive and process. In
4399 // particular the system has been known to sleep
4400 // before this message can be processed.
4401 p.writeInt64(timeReceived);
4402 break;
4403 }
4404
Etan Cohend3652192014-06-20 08:28:44 -07004405 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4406 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004407 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4408
4409 // Unfortunately, NITZ time is not poll/update like everything
4410 // else in the system. So, if the upstream client isn't connected,
4411 // keep a copy of the last NITZ response (with receive time noted
4412 // above) around so we can deliver it when it is connected
4413
4414 if (s_lastNITZTimeData != NULL) {
4415 free (s_lastNITZTimeData);
4416 s_lastNITZTimeData = NULL;
4417 }
4418
4419 s_lastNITZTimeData = malloc(p.dataSize());
4420 s_lastNITZTimeDataSize = p.dataSize();
4421 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4422 }
4423
4424 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4425 // FIXME The java code should handshake here to release wake lock
4426
4427 if (shouldScheduleTimeout) {
4428 // Cancel the previous request
4429 if (s_last_wake_timeout_info != NULL) {
4430 s_last_wake_timeout_info->userParam = (void *)1;
4431 }
4432
4433 s_last_wake_timeout_info
4434 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4435 &TIMEVAL_WAKE_TIMEOUT);
4436 }
4437
4438 // Normal exit
4439 return;
4440
4441error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004442 if (shouldScheduleTimeout) {
4443 releaseWakeLock();
4444 }
4445}
4446
Wink Saville7f856802009-06-09 10:23:37 -07004447/** FIXME generalize this if you track UserCAllbackInfo, clear it
4448 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004449*/
4450static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004451internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004452 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004453{
4454 struct timeval myRelativeTime;
4455 UserCallbackInfo *p_info;
4456
4457 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4458
Wink Saville7f856802009-06-09 10:23:37 -07004459 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004460 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004461
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004462 if (relativeTime == NULL) {
4463 /* treat null parameter as a 0 relative time */
4464 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4465 } else {
4466 /* FIXME I think event_add's tv param is really const anyway */
4467 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4468 }
4469
4470 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4471
4472 ril_timer_add(&(p_info->event), &myRelativeTime);
4473
4474 triggerEvLoop();
4475 return p_info;
4476}
4477
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004478
4479extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004480RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4481 const struct timeval *relativeTime) {
4482 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004483}
4484
4485const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004486failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004487 switch(e) {
4488 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004489 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004490 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4491 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4492 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4493 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4494 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4495 case RIL_E_CANCELLED: return "E_CANCELLED";
4496 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4497 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4498 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004499 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004500 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004501#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004502 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4503 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4504#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004505 default: return "<unknown error>";
4506 }
4507}
4508
4509const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004510radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004511 switch(s) {
4512 case RADIO_STATE_OFF: return "RADIO_OFF";
4513 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4514 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4515 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4516 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004517 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4518 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4519 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4520 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4521 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004522 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004523 default: return "<unknown state>";
4524 }
4525}
4526
4527const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004528callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529 switch(s) {
4530 case RIL_CALL_ACTIVE : return "ACTIVE";
4531 case RIL_CALL_HOLDING: return "HOLDING";
4532 case RIL_CALL_DIALING: return "DIALING";
4533 case RIL_CALL_ALERTING: return "ALERTING";
4534 case RIL_CALL_INCOMING: return "INCOMING";
4535 case RIL_CALL_WAITING: return "WAITING";
4536 default: return "<unknown state>";
4537 }
4538}
4539
4540const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004541requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004542/*
4543 cat libs/telephony/ril_commands.h \
4544 | egrep "^ *{RIL_" \
4545 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4546
4547
4548 cat libs/telephony/ril_unsol_commands.h \
4549 | egrep "^ *{RIL_" \
4550 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4551
4552*/
4553 switch(request) {
4554 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4555 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4556 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4557 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4558 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4559 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4560 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4561 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4562 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4563 case RIL_REQUEST_DIAL: return "DIAL";
4564 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4565 case RIL_REQUEST_HANGUP: return "HANGUP";
4566 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4567 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4568 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4569 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4570 case RIL_REQUEST_UDUB: return "UDUB";
4571 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4572 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004573 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4574 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004575 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4576 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4577 case RIL_REQUEST_DTMF: return "DTMF";
4578 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4579 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004580 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004581 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4582 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4583 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4584 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4585 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4586 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4587 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4588 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4589 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4590 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4591 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4592 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4593 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004594 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004595 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4596 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4597 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4598 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4599 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4600 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4601 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4602 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4603 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4604 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4605 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4606 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4607 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4608 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4609 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4610 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4611 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004612 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4613 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004614 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4615 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4616 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004617 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4618 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004619 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4620 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4621 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4622 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4623 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4624 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4625 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4626 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004627 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004628 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4629 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4630 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4631 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4632 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4633 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4634 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4635 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4636 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4637 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004638 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4639 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4640 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4641 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4642 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004643 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004644 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4645 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4646 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4647 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004648 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4649 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4650 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004651 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004652 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004653 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004654 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004655 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4656 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004657 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004658 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4659 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004660 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004661 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4662 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004663 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4664 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4665 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4666 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Etan Cohend3652192014-06-20 08:28:44 -07004667 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4668 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004669 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4670 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004671 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4672 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004673 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004674 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4675 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004676 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 -08004677 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4678 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4679 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4680 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4681 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4682 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4683 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4684 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4685 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4686 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4687 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4688 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4689 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004690 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004691 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004692 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4693 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4694 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4695 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004696 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4697 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4698 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4699 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4700 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004701 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004702 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004703 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004704 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004705 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4706 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004707 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004708 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004709 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004710 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004711 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4712 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4713 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004714 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07004715 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004716 default: return "<unknown request>";
4717 }
4718}
4719
Etan Cohend3652192014-06-20 08:28:44 -07004720const char *
4721rilSocketIdToString(RIL_SOCKET_ID socket_id)
4722{
4723 switch(socket_id) {
4724 case RIL_SOCKET_1:
4725 return "RIL_SOCKET_1";
4726#if (SIM_COUNT >= 2)
4727 case RIL_SOCKET_2:
4728 return "RIL_SOCKET_2";
4729#endif
4730#if (SIM_COUNT >= 3)
4731 case RIL_SOCKET_3:
4732 return "RIL_SOCKET_3";
4733#endif
4734#if (SIM_COUNT >= 4)
4735 case RIL_SOCKET_4:
4736 return "RIL_SOCKET_4";
4737#endif
4738 default:
4739 return "not a valid RIL";
4740 }
4741}
4742
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004743} /* namespace android */