blob: a1105b42c80857a775dd386b5cfab0f929c3a27d [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);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700280static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800281static int responseInts(Parcel &p, void *response, size_t responselen);
282static int responseStrings(Parcel &p, void *response, size_t responselen);
283static int responseString(Parcel &p, void *response, size_t responselen);
284static int responseVoid(Parcel &p, void *response, size_t responselen);
285static int responseCallList(Parcel &p, void *response, size_t responselen);
286static int responseSMS(Parcel &p, void *response, size_t responselen);
287static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
288static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700289static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800290static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800291static int responseRaw(Parcel &p, void *response, size_t responselen);
292static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700294static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
295static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700296static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800297static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700298static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
299static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
300static int responseCallRing(Parcel &p, void *response, size_t responselen);
301static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
302static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800303static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700304static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700305static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700306static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700307static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000308static int responseSSData(Parcel &p, void *response, size_t responselen);
309
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800310static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
311static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
312static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
313
Amit Mahajan54563d32014-11-22 00:54:49 +0000314static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
315
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700317#if defined(ANDROID_MULTI_SIM)
318extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
319 size_t datalen, RIL_SOCKET_ID socket_id);
320#else
Wink Saville7f856802009-06-09 10:23:37 -0700321extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800322 size_t datalen);
323#endif
Etan Cohend3652192014-06-20 08:28:44 -0700324#endif
325
326#if defined(ANDROID_MULTI_SIM)
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
330#else
331#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
332#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
333#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
334#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
Wink Saville7f856802009-06-09 10:23:37 -0700336static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700337 (RIL_TimedCallback callback, void *param,
338 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800339
340/** Index == requestNumber */
341static CommandInfo s_commands[] = {
342#include "ril_commands.h"
343};
344
345static UnsolResponseInfo s_unsolResponses[] = {
346#include "ril_unsol_commands.h"
347};
348
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800349/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
350 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
351 radio state message and store it. Every time there is a change in Radio State
352 check to see if voice radio tech changes and notify telephony
353 */
354int voiceRadioTech = -1;
355
356/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
357 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
358 source from radio state and store it. Every time there is a change in Radio State
359 check to see if subscription source changed and notify telephony
360 */
361int cdmaSubscriptionSource = -1;
362
363/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
364 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
365 check to see if SIM/RUIM status changed and notify telephony
366 */
367int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800368
Etan Cohend3652192014-06-20 08:28:44 -0700369static char * RIL_getRilSocketName() {
370 return rild;
371}
372
373extern "C"
374void RIL_setRilSocketName(char * s) {
375 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
376}
377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700379strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 size_t stringlen;
381 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700382
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800383 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700384
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800385 return strndup16to8(s16, stringlen);
386}
387
Wink Saville8b4e4f72014-10-17 15:01:45 -0700388static status_t
389readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
390 size_t s16Len;
391 const char16_t *s16;
392
393 s16 = p.readString16Inplace(&s16Len);
394 if (s16 == NULL) {
395 return NO_MEMORY;
396 }
397 size_t strLen = strnlen16to8(s16, s16Len);
398 if ((strLen + 1) > maxLen) {
399 return NO_MEMORY;
400 }
401 if (strncpy16to8(str, s16, strLen) == NULL) {
402 return NO_MEMORY;
403 } else {
404 return NO_ERROR;
405 }
406}
407
Wink Savillef4c4d362009-04-02 01:37:03 -0700408static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 char16_t *s16;
410 size_t s16_len;
411 s16 = strdup8to16(s, &s16_len);
412 p.writeString16(s16, s16_len);
413 free(s16);
414}
415
416
417static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700418memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800419 if (s != NULL) {
420 memset (s, 0, strlen(s));
421 }
422}
423
424void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
425 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700426 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 // do nothing -- the data reference lives longer than the Parcel object
428}
429
Wink Saville7f856802009-06-09 10:23:37 -0700430/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 * To be called from dispatch thread
432 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700433 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800434 */
435static void
Etan Cohend3652192014-06-20 08:28:44 -0700436issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437 RequestInfo *pRI;
438 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700439 /* Hook for current context */
440 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
441 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
442 /* pendingRequestsHook refer to &s_pendingRequests */
443 RequestInfo** pendingRequestsHook = &s_pendingRequests;
444
445#if (SIM_COUNT == 2)
446 if (socket_id == RIL_SOCKET_2) {
447 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
448 pendingRequestsHook = &s_pendingRequests_socket2;
449 }
450#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451
452 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
453
454 pRI->local = 1;
455 pRI->token = 0xffffffff; // token is not used in this context
456 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700457 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458
Etan Cohend3652192014-06-20 08:28:44 -0700459 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460 assert (ret == 0);
461
Etan Cohend3652192014-06-20 08:28:44 -0700462 pRI->p_next = *pendingRequestsHook;
463 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464
Etan Cohend3652192014-06-20 08:28:44 -0700465 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800466 assert (ret == 0);
467
Wink Saville8eb2a122012-11-19 16:05:13 -0800468 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800469
Etan Cohend3652192014-06-20 08:28:44 -0700470 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471}
472
473
474
475static int
Etan Cohend3652192014-06-20 08:28:44 -0700476processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800477 Parcel p;
478 status_t status;
479 int32_t request;
480 int32_t token;
481 RequestInfo *pRI;
482 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700483 /* Hook for current context */
484 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
485 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
486 /* pendingRequestsHook refer to &s_pendingRequests */
487 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800488
489 p.setData((uint8_t *) buffer, buflen);
490
491 // status checked at end
492 status = p.readInt32(&request);
493 status = p.readInt32 (&token);
494
Etan Cohend3652192014-06-20 08:28:44 -0700495#if (SIM_COUNT >= 2)
496 if (socket_id == RIL_SOCKET_2) {
497 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
498 pendingRequestsHook = &s_pendingRequests_socket2;
499 }
500#if (SIM_COUNT >= 3)
501 else if (socket_id == RIL_SOCKET_3) {
502 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
503 pendingRequestsHook = &s_pendingRequests_socket3;
504 }
505#endif
506#if (SIM_COUNT >= 4)
507 else if (socket_id == RIL_SOCKET_4) {
508 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
509 pendingRequestsHook = &s_pendingRequests_socket4;
510 }
511#endif
512#endif
513
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800515 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 return 0;
517 }
518
519 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700520 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800521 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700523 pErr.writeInt32 (RESPONSE_SOLICITED);
524 pErr.writeInt32 (token);
525 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
526
527 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800528 return 0;
529 }
530
531
532 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
533
534 pRI->token = token;
535 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700536 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537
Etan Cohend3652192014-06-20 08:28:44 -0700538 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539 assert (ret == 0);
540
Etan Cohend3652192014-06-20 08:28:44 -0700541 pRI->p_next = *pendingRequestsHook;
542 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543
Etan Cohend3652192014-06-20 08:28:44 -0700544 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545 assert (ret == 0);
546
547/* sLastDispatchedToken = token; */
548
Wink Saville7f856802009-06-09 10:23:37 -0700549 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800550
551 return 0;
552}
553
554static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700555invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800556 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800557 pRI->token, requestToString(pRI->pCI->requestNumber));
558}
559
560/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700561static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700562dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800563 clearPrintBuf;
564 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700565 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800566}
567
568/** Callee expects const char * */
569static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700570dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800571 status_t status;
572 size_t datalen;
573 size_t stringlen;
574 char *string8 = NULL;
575
576 string8 = strdupReadString(p);
577
578 startRequest;
579 appendPrintBuf("%s%s", printBuf, string8);
580 closeRequest;
581 printRequest(pRI->token, pRI->pCI->requestNumber);
582
Etan Cohend3652192014-06-20 08:28:44 -0700583 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
584 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800585
586#ifdef MEMSET_FREED
587 memsetString(string8);
588#endif
589
590 free(string8);
591 return;
592invalid:
593 invalidCommandBlock(pRI);
594 return;
595}
596
597/** Callee expects const char ** */
598static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700599dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800600 int32_t countStrings;
601 status_t status;
602 size_t datalen;
603 char **pStrings;
604
605 status = p.readInt32 (&countStrings);
606
607 if (status != NO_ERROR) {
608 goto invalid;
609 }
610
611 startRequest;
612 if (countStrings == 0) {
613 // just some non-null pointer
614 pStrings = (char **)alloca(sizeof(char *));
615 datalen = 0;
616 } else if (((int)countStrings) == -1) {
617 pStrings = NULL;
618 datalen = 0;
619 } else {
620 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700621
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800622 pStrings = (char **)alloca(datalen);
623
624 for (int i = 0 ; i < countStrings ; i++) {
625 pStrings[i] = strdupReadString(p);
626 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
627 }
628 }
629 removeLastChar;
630 closeRequest;
631 printRequest(pRI->token, pRI->pCI->requestNumber);
632
Etan Cohend3652192014-06-20 08:28:44 -0700633 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800634
635 if (pStrings != NULL) {
636 for (int i = 0 ; i < countStrings ; i++) {
637#ifdef MEMSET_FREED
638 memsetString (pStrings[i]);
639#endif
640 free(pStrings[i]);
641 }
642
643#ifdef MEMSET_FREED
644 memset(pStrings, 0, datalen);
645#endif
646 }
Wink Saville7f856802009-06-09 10:23:37 -0700647
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800648 return;
649invalid:
650 invalidCommandBlock(pRI);
651 return;
652}
653
654/** Callee expects const int * */
655static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700656dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800657 int32_t count;
658 status_t status;
659 size_t datalen;
660 int *pInts;
661
662 status = p.readInt32 (&count);
663
664 if (status != NO_ERROR || count == 0) {
665 goto invalid;
666 }
667
668 datalen = sizeof(int) * count;
669 pInts = (int *)alloca(datalen);
670
671 startRequest;
672 for (int i = 0 ; i < count ; i++) {
673 int32_t t;
674
675 status = p.readInt32(&t);
676 pInts[i] = (int)t;
677 appendPrintBuf("%s%d,", printBuf, t);
678
679 if (status != NO_ERROR) {
680 goto invalid;
681 }
682 }
683 removeLastChar;
684 closeRequest;
685 printRequest(pRI->token, pRI->pCI->requestNumber);
686
Etan Cohend3652192014-06-20 08:28:44 -0700687 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
688 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800689
690#ifdef MEMSET_FREED
691 memset(pInts, 0, datalen);
692#endif
693
694 return;
695invalid:
696 invalidCommandBlock(pRI);
697 return;
698}
699
700
Wink Saville7f856802009-06-09 10:23:37 -0700701/**
702 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800703 * Payload is:
704 * int32_t status
705 * String pdu
706 */
707static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700708dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800709 RIL_SMS_WriteArgs args;
710 int32_t t;
711 status_t status;
712
713 memset (&args, 0, sizeof(args));
714
715 status = p.readInt32(&t);
716 args.status = (int)t;
717
718 args.pdu = strdupReadString(p);
719
720 if (status != NO_ERROR || args.pdu == NULL) {
721 goto invalid;
722 }
723
724 args.smsc = strdupReadString(p);
725
726 startRequest;
727 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
728 (char*)args.pdu, (char*)args.smsc);
729 closeRequest;
730 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700731
Etan Cohend3652192014-06-20 08:28:44 -0700732 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800733
734#ifdef MEMSET_FREED
735 memsetString (args.pdu);
736#endif
737
738 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700739
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800740#ifdef MEMSET_FREED
741 memset(&args, 0, sizeof(args));
742#endif
743
744 return;
745invalid:
746 invalidCommandBlock(pRI);
747 return;
748}
749
Wink Saville7f856802009-06-09 10:23:37 -0700750/**
751 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800752 * Payload is:
753 * String address
754 * int32_t clir
755 */
756static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700757dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800758 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800759 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800760 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800761 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800762 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800763 status_t status;
764
765 memset (&dial, 0, sizeof(dial));
766
767 dial.address = strdupReadString(p);
768
769 status = p.readInt32(&t);
770 dial.clir = (int)t;
771
772 if (status != NO_ERROR || dial.address == NULL) {
773 goto invalid;
774 }
775
Wink Saville3a4840b2010-04-07 13:29:58 -0700776 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800777 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800778 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800779 } else {
780 status = p.readInt32(&uusPresent);
781
782 if (status != NO_ERROR) {
783 goto invalid;
784 }
785
786 if (uusPresent == 0) {
787 dial.uusInfo = NULL;
788 } else {
789 int32_t len;
790
791 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
792
793 status = p.readInt32(&t);
794 uusInfo.uusType = (RIL_UUS_Type) t;
795
796 status = p.readInt32(&t);
797 uusInfo.uusDcs = (RIL_UUS_DCS) t;
798
799 status = p.readInt32(&len);
800 if (status != NO_ERROR) {
801 goto invalid;
802 }
803
804 // The java code writes -1 for null arrays
805 if (((int) len) == -1) {
806 uusInfo.uusData = NULL;
807 len = 0;
808 } else {
809 uusInfo.uusData = (char*) p.readInplace(len);
810 }
811
812 uusInfo.uusLength = len;
813 dial.uusInfo = &uusInfo;
814 }
Wink Saville7bce0822010-01-08 15:20:12 -0800815 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800816 }
817
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800818 startRequest;
819 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800820 if (uusPresent) {
821 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
822 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
823 dial.uusInfo->uusLength);
824 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800825 closeRequest;
826 printRequest(pRI->token, pRI->pCI->requestNumber);
827
Etan Cohend3652192014-06-20 08:28:44 -0700828 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800829
830#ifdef MEMSET_FREED
831 memsetString (dial.address);
832#endif
833
834 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700835
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800836#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800837 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838 memset(&dial, 0, sizeof(dial));
839#endif
840
841 return;
842invalid:
843 invalidCommandBlock(pRI);
844 return;
845}
846
Wink Saville7f856802009-06-09 10:23:37 -0700847/**
848 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800849 * Payload is:
850 * int32_t command
851 * int32_t fileid
852 * String path
853 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700854 * String data
855 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800856 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800857 */
858static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700859dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800860 union RIL_SIM_IO {
861 RIL_SIM_IO_v6 v6;
862 RIL_SIM_IO_v5 v5;
863 } simIO;
864
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800865 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800866 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867 status_t status;
868
869 memset (&simIO, 0, sizeof(simIO));
870
Wink Saville7f856802009-06-09 10:23:37 -0700871 // note we only check status at the end
872
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800874 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800875
876 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800877 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878
Wink Savillec0114b32011-02-18 10:14:07 -0800879 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880
881 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800882 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800883
884 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800885 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800886
887 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800888 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800889
Wink Savillec0114b32011-02-18 10:14:07 -0800890 simIO.v6.data = strdupReadString(p);
891 simIO.v6.pin2 = strdupReadString(p);
892 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800893
894 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800895 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
896 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
897 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
898 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800899 closeRequest;
900 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700901
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800902 if (status != NO_ERROR) {
903 goto invalid;
904 }
905
Wink Savillec0114b32011-02-18 10:14:07 -0800906 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700907 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800908
909#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800910 memsetString (simIO.v6.path);
911 memsetString (simIO.v6.data);
912 memsetString (simIO.v6.pin2);
913 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800914#endif
915
Wink Savillec0114b32011-02-18 10:14:07 -0800916 free (simIO.v6.path);
917 free (simIO.v6.data);
918 free (simIO.v6.pin2);
919 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700920
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800921#ifdef MEMSET_FREED
922 memset(&simIO, 0, sizeof(simIO));
923#endif
924
925 return;
926invalid:
927 invalidCommandBlock(pRI);
928 return;
929}
930
931/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800932 * Callee expects const RIL_SIM_APDU *
933 * Payload is:
934 * int32_t sessionid
935 * int32_t cla
936 * int32_t instruction
937 * int32_t p1, p2, p3
938 * String data
939 */
940static void
941dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
942 int32_t t;
943 status_t status;
944 RIL_SIM_APDU apdu;
945
946 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
947
948 // Note we only check status at the end. Any single failure leads to
949 // subsequent reads filing.
950 status = p.readInt32(&t);
951 apdu.sessionid = (int)t;
952
953 status = p.readInt32(&t);
954 apdu.cla = (int)t;
955
956 status = p.readInt32(&t);
957 apdu.instruction = (int)t;
958
959 status = p.readInt32(&t);
960 apdu.p1 = (int)t;
961
962 status = p.readInt32(&t);
963 apdu.p2 = (int)t;
964
965 status = p.readInt32(&t);
966 apdu.p3 = (int)t;
967
968 apdu.data = strdupReadString(p);
969
970 startRequest;
971 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
972 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
973 apdu.p3, (char*)apdu.data);
974 closeRequest;
975 printRequest(pRI->token, pRI->pCI->requestNumber);
976
977 if (status != NO_ERROR) {
978 goto invalid;
979 }
980
Etan Cohend3652192014-06-20 08:28:44 -0700981 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800982
983#ifdef MEMSET_FREED
984 memsetString(apdu.data);
985#endif
986 free(apdu.data);
987
988#ifdef MEMSET_FREED
989 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
990#endif
991
992 return;
993invalid:
994 invalidCommandBlock(pRI);
995 return;
996}
997
998
999/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001000 * Callee expects const RIL_CallForwardInfo *
1001 * Payload is:
1002 * int32_t status/action
1003 * int32_t reason
1004 * int32_t serviceCode
1005 * int32_t toa
1006 * String number (0 length -> null)
1007 * int32_t timeSeconds
1008 */
Wink Saville7f856802009-06-09 10:23:37 -07001009static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001010dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001011 RIL_CallForwardInfo cff;
1012 int32_t t;
1013 status_t status;
1014
1015 memset (&cff, 0, sizeof(cff));
1016
Wink Saville7f856802009-06-09 10:23:37 -07001017 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001018
1019 status = p.readInt32(&t);
1020 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001021
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001022 status = p.readInt32(&t);
1023 cff.reason = (int)t;
1024
1025 status = p.readInt32(&t);
1026 cff.serviceClass = (int)t;
1027
1028 status = p.readInt32(&t);
1029 cff.toa = (int)t;
1030
1031 cff.number = strdupReadString(p);
1032
1033 status = p.readInt32(&t);
1034 cff.timeSeconds = (int)t;
1035
1036 if (status != NO_ERROR) {
1037 goto invalid;
1038 }
1039
1040 // special case: number 0-length fields is null
1041
1042 if (cff.number != NULL && strlen (cff.number) == 0) {
1043 cff.number = NULL;
1044 }
1045
1046 startRequest;
1047 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1048 cff.status, cff.reason, cff.serviceClass, cff.toa,
1049 (char*)cff.number, cff.timeSeconds);
1050 closeRequest;
1051 printRequest(pRI->token, pRI->pCI->requestNumber);
1052
Etan Cohend3652192014-06-20 08:28:44 -07001053 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001054
1055#ifdef MEMSET_FREED
1056 memsetString(cff.number);
1057#endif
1058
1059 free (cff.number);
1060
1061#ifdef MEMSET_FREED
1062 memset(&cff, 0, sizeof(cff));
1063#endif
1064
1065 return;
1066invalid:
1067 invalidCommandBlock(pRI);
1068 return;
1069}
1070
1071
Wink Saville7f856802009-06-09 10:23:37 -07001072static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001073dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001074 int32_t len;
1075 status_t status;
1076 const void *data;
1077
1078 status = p.readInt32(&len);
1079
1080 if (status != NO_ERROR) {
1081 goto invalid;
1082 }
1083
1084 // The java code writes -1 for null arrays
1085 if (((int)len) == -1) {
1086 data = NULL;
1087 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001088 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001089
1090 data = p.readInplace(len);
1091
1092 startRequest;
1093 appendPrintBuf("%sraw_size=%d", printBuf, len);
1094 closeRequest;
1095 printRequest(pRI->token, pRI->pCI->requestNumber);
1096
Etan Cohend3652192014-06-20 08:28:44 -07001097 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001098
1099 return;
1100invalid:
1101 invalidCommandBlock(pRI);
1102 return;
1103}
1104
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001105static status_t
1106constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001107 int32_t t;
1108 uint8_t ut;
1109 status_t status;
1110 int32_t digitCount;
1111 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001112
Wink Savillef4c4d362009-04-02 01:37:03 -07001113 memset(&rcsm, 0, sizeof(rcsm));
1114
1115 status = p.readInt32(&t);
1116 rcsm.uTeleserviceID = (int) t;
1117
1118 status = p.read(&ut,sizeof(ut));
1119 rcsm.bIsServicePresent = (uint8_t) ut;
1120
1121 status = p.readInt32(&t);
1122 rcsm.uServicecategory = (int) t;
1123
1124 status = p.readInt32(&t);
1125 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1126
1127 status = p.readInt32(&t);
1128 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1129
1130 status = p.readInt32(&t);
1131 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1132
1133 status = p.readInt32(&t);
1134 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1135
1136 status = p.read(&ut,sizeof(ut));
1137 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1138
1139 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1140 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1141 status = p.read(&ut,sizeof(ut));
1142 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1143 }
1144
Wink Saville7f856802009-06-09 10:23:37 -07001145 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001146 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1147
Wink Saville7f856802009-06-09 10:23:37 -07001148 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001149 rcsm.sSubAddress.odd = (uint8_t) ut;
1150
1151 status = p.read(&ut,sizeof(ut));
1152 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1153
1154 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001155 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1156 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001157 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1158 }
1159
Wink Saville7f856802009-06-09 10:23:37 -07001160 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001161 rcsm.uBearerDataLen = (int) t;
1162
1163 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001164 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1165 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001166 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1167 }
1168
1169 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001170 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001171 }
1172
1173 startRequest;
1174 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001175 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001176 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001177 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001179
Wink Savillef4c4d362009-04-02 01:37:03 -07001180 printRequest(pRI->token, pRI->pCI->requestNumber);
1181
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001182 return status;
1183}
1184
1185static void
1186dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1187 RIL_CDMA_SMS_Message rcsm;
1188
1189 ALOGD("dispatchCdmaSms");
1190 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1191 goto invalid;
1192 }
1193
Etan Cohend3652192014-06-20 08:28:44 -07001194 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001195
1196#ifdef MEMSET_FREED
1197 memset(&rcsm, 0, sizeof(rcsm));
1198#endif
1199
1200 return;
1201
1202invalid:
1203 invalidCommandBlock(pRI);
1204 return;
1205}
1206
Wink Saville7f856802009-06-09 10:23:37 -07001207static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001208dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1209 RIL_IMS_SMS_Message rism;
1210 RIL_CDMA_SMS_Message rcsm;
1211
1212 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1213
1214 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1215 goto invalid;
1216 }
1217 memset(&rism, 0, sizeof(rism));
1218 rism.tech = RADIO_TECH_3GPP2;
1219 rism.retry = retry;
1220 rism.messageRef = messageRef;
1221 rism.message.cdmaMessage = &rcsm;
1222
Etan Cohend3652192014-06-20 08:28:44 -07001223 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001224 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001225 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001226
1227#ifdef MEMSET_FREED
1228 memset(&rcsm, 0, sizeof(rcsm));
1229 memset(&rism, 0, sizeof(rism));
1230#endif
1231
1232 return;
1233
1234invalid:
1235 invalidCommandBlock(pRI);
1236 return;
1237}
1238
1239static void
1240dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1241 RIL_IMS_SMS_Message rism;
1242 int32_t countStrings;
1243 status_t status;
1244 size_t datalen;
1245 char **pStrings;
1246 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1247
1248 status = p.readInt32 (&countStrings);
1249
1250 if (status != NO_ERROR) {
1251 goto invalid;
1252 }
1253
1254 memset(&rism, 0, sizeof(rism));
1255 rism.tech = RADIO_TECH_3GPP;
1256 rism.retry = retry;
1257 rism.messageRef = messageRef;
1258
1259 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001260 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1261 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001262 if (countStrings == 0) {
1263 // just some non-null pointer
1264 pStrings = (char **)alloca(sizeof(char *));
1265 datalen = 0;
1266 } else if (((int)countStrings) == -1) {
1267 pStrings = NULL;
1268 datalen = 0;
1269 } else {
1270 datalen = sizeof(char *) * countStrings;
1271
1272 pStrings = (char **)alloca(datalen);
1273
1274 for (int i = 0 ; i < countStrings ; i++) {
1275 pStrings[i] = strdupReadString(p);
1276 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1277 }
1278 }
1279 removeLastChar;
1280 closeRequest;
1281 printRequest(pRI->token, pRI->pCI->requestNumber);
1282
1283 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001284 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001285 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001286 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001287
1288 if (pStrings != NULL) {
1289 for (int i = 0 ; i < countStrings ; i++) {
1290#ifdef MEMSET_FREED
1291 memsetString (pStrings[i]);
1292#endif
1293 free(pStrings[i]);
1294 }
1295
1296#ifdef MEMSET_FREED
1297 memset(pStrings, 0, datalen);
1298#endif
1299 }
1300
1301#ifdef MEMSET_FREED
1302 memset(&rism, 0, sizeof(rism));
1303#endif
1304 return;
1305invalid:
1306 ALOGE("dispatchImsGsmSms invalid block");
1307 invalidCommandBlock(pRI);
1308 return;
1309}
1310
1311static void
1312dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1313 int32_t t;
1314 status_t status = p.readInt32(&t);
1315 RIL_RadioTechnologyFamily format;
1316 uint8_t retry;
1317 int32_t messageRef;
1318
1319 ALOGD("dispatchImsSms");
1320 if (status != NO_ERROR) {
1321 goto invalid;
1322 }
1323 format = (RIL_RadioTechnologyFamily) t;
1324
1325 // read retry field
1326 status = p.read(&retry,sizeof(retry));
1327 if (status != NO_ERROR) {
1328 goto invalid;
1329 }
1330 // read messageRef field
1331 status = p.read(&messageRef,sizeof(messageRef));
1332 if (status != NO_ERROR) {
1333 goto invalid;
1334 }
1335
1336 if (RADIO_TECH_3GPP == format) {
1337 dispatchImsGsmSms(p, pRI, retry, messageRef);
1338 } else if (RADIO_TECH_3GPP2 == format) {
1339 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1340 } else {
1341 ALOGE("requestImsSendSMS invalid format value =%d", format);
1342 }
1343
1344 return;
1345
1346invalid:
1347 invalidCommandBlock(pRI);
1348 return;
1349}
1350
1351static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001352dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1353 RIL_CDMA_SMS_Ack rcsa;
1354 int32_t t;
1355 status_t status;
1356 int32_t digitCount;
1357
1358 memset(&rcsa, 0, sizeof(rcsa));
1359
1360 status = p.readInt32(&t);
1361 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1362
1363 status = p.readInt32(&t);
1364 rcsa.uSMSCauseCode = (int) t;
1365
1366 if (status != NO_ERROR) {
1367 goto invalid;
1368 }
1369
1370 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001371 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1372 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001373 closeRequest;
1374
1375 printRequest(pRI->token, pRI->pCI->requestNumber);
1376
Etan Cohend3652192014-06-20 08:28:44 -07001377 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001378
1379#ifdef MEMSET_FREED
1380 memset(&rcsa, 0, sizeof(rcsa));
1381#endif
1382
1383 return;
1384
1385invalid:
1386 invalidCommandBlock(pRI);
1387 return;
1388}
1389
Wink Savillea592eeb2009-05-22 13:26:36 -07001390static void
1391dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1392 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001393 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001394 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001395
Wink Savillea592eeb2009-05-22 13:26:36 -07001396 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001397 if (status != NO_ERROR) {
1398 goto invalid;
1399 }
1400
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001401 {
1402 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1403 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001404
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001405 startRequest;
1406 for (int i = 0 ; i < num ; i++ ) {
1407 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001408
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001409 status = p.readInt32(&t);
1410 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001411
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001412 status = p.readInt32(&t);
1413 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001414
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001415 status = p.readInt32(&t);
1416 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001417
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001418 status = p.readInt32(&t);
1419 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001420
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001421 status = p.readInt32(&t);
1422 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001423
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001424 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1425 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1426 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1427 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1428 gsmBci[i].selected);
1429 }
1430 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001431
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001432 if (status != NO_ERROR) {
1433 goto invalid;
1434 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001435
Etan Cohend3652192014-06-20 08:28:44 -07001436 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001437 gsmBciPtrs,
1438 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001439 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001440
1441#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001442 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1443 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001444#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001445 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001446
1447 return;
1448
1449invalid:
1450 invalidCommandBlock(pRI);
1451 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001452}
Wink Savillef4c4d362009-04-02 01:37:03 -07001453
Wink Savillea592eeb2009-05-22 13:26:36 -07001454static void
1455dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1456 int32_t t;
1457 status_t status;
1458 int32_t num;
1459
1460 status = p.readInt32(&num);
1461 if (status != NO_ERROR) {
1462 goto invalid;
1463 }
1464
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001465 {
1466 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1467 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001468
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001469 startRequest;
1470 for (int i = 0 ; i < num ; i++ ) {
1471 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001472
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001473 status = p.readInt32(&t);
1474 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001475
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 status = p.readInt32(&t);
1477 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001478
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001479 status = p.readInt32(&t);
1480 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001481
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001482 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1483 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1484 cdmaBci[i].language, cdmaBci[i].selected);
1485 }
1486 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001487
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001488 if (status != NO_ERROR) {
1489 goto invalid;
1490 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001491
Etan Cohend3652192014-06-20 08:28:44 -07001492 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001493 cdmaBciPtrs,
1494 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001495 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001496
1497#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001498 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1499 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001500#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001501 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001502
1503 return;
1504
1505invalid:
1506 invalidCommandBlock(pRI);
1507 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001508}
1509
1510static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1511 RIL_CDMA_SMS_WriteArgs rcsw;
1512 int32_t t;
1513 uint32_t ut;
1514 uint8_t uct;
1515 status_t status;
1516 int32_t digitCount;
1517
1518 memset(&rcsw, 0, sizeof(rcsw));
1519
1520 status = p.readInt32(&t);
1521 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001522
Wink Savillef4c4d362009-04-02 01:37:03 -07001523 status = p.readInt32(&t);
1524 rcsw.message.uTeleserviceID = (int) t;
1525
1526 status = p.read(&uct,sizeof(uct));
1527 rcsw.message.bIsServicePresent = (uint8_t) uct;
1528
1529 status = p.readInt32(&t);
1530 rcsw.message.uServicecategory = (int) t;
1531
1532 status = p.readInt32(&t);
1533 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1534
1535 status = p.readInt32(&t);
1536 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1537
1538 status = p.readInt32(&t);
1539 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1540
1541 status = p.readInt32(&t);
1542 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1543
1544 status = p.read(&uct,sizeof(uct));
1545 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1546
1547 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1548 status = p.read(&uct,sizeof(uct));
1549 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1550 }
1551
Wink Savillea592eeb2009-05-22 13:26:36 -07001552 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001553 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1554
Wink Savillea592eeb2009-05-22 13:26:36 -07001555 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001556 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1557
1558 status = p.read(&uct,sizeof(uct));
1559 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1560
1561 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001562 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001563 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1564 }
1565
Wink Savillea592eeb2009-05-22 13:26:36 -07001566 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001567 rcsw.message.uBearerDataLen = (int) t;
1568
1569 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001570 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001571 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1572 }
1573
1574 if (status != NO_ERROR) {
1575 goto invalid;
1576 }
1577
1578 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001579 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1580 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1581 message.sAddress.number_mode=%d, \
1582 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001583 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001584 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1585 rcsw.message.sAddress.number_mode,
1586 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001587 closeRequest;
1588
1589 printRequest(pRI->token, pRI->pCI->requestNumber);
1590
Etan Cohend3652192014-06-20 08:28:44 -07001591 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001592
1593#ifdef MEMSET_FREED
1594 memset(&rcsw, 0, sizeof(rcsw));
1595#endif
1596
1597 return;
1598
1599invalid:
1600 invalidCommandBlock(pRI);
1601 return;
1602
1603}
1604
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001605// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1606// Version 4 of the RIL interface adds a new PDP type parameter to support
1607// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1608// RIL, remove the parameter from the request.
1609static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1610 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1611 const int numParamsRilV3 = 6;
1612
1613 // The first bytes of the RIL parcel contain the request number and the
1614 // serial number - see processCommandBuffer(). Copy them over too.
1615 int pos = p.dataPosition();
1616
1617 int numParams = p.readInt32();
1618 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1619 Parcel p2;
1620 p2.appendFrom(&p, 0, pos);
1621 p2.writeInt32(numParamsRilV3);
1622 for(int i = 0; i < numParamsRilV3; i++) {
1623 p2.writeString16(p.readString16());
1624 }
1625 p2.setDataPosition(pos);
1626 dispatchStrings(p2, pRI);
1627 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001628 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001629 dispatchStrings(p, pRI);
1630 }
1631}
1632
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001633// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1634// When all RILs handle this request, this function can be removed and
1635// the request can be sent directly to the RIL using dispatchVoid.
1636static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001637 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001638
1639 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1640 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1641 }
1642
1643 // RILs that support RADIO_STATE_ON should support this request.
1644 if (RADIO_STATE_ON == state) {
1645 dispatchVoid(p, pRI);
1646 return;
1647 }
1648
1649 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1650 // will not support this new request either and decode Voice Radio Technology
1651 // from Radio State
1652 voiceRadioTech = decodeVoiceRadioTechnology(state);
1653
1654 if (voiceRadioTech < 0)
1655 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1656 else
1657 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1658}
1659
1660// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1661// When all RILs handle this request, this function can be removed and
1662// the request can be sent directly to the RIL using dispatchVoid.
1663static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001664 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001665
1666 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1667 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1668 }
1669
1670 // RILs that support RADIO_STATE_ON should support this request.
1671 if (RADIO_STATE_ON == state) {
1672 dispatchVoid(p, pRI);
1673 return;
1674 }
1675
1676 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1677 // will not support this new request either and decode CDMA Subscription Source
1678 // from Radio State
1679 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1680
1681 if (cdmaSubscriptionSource < 0)
1682 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1683 else
1684 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1685}
1686
Sungmin Choi75697532013-04-26 15:04:45 -07001687static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1688{
1689 RIL_InitialAttachApn pf;
1690 int32_t t;
1691 status_t status;
1692
1693 memset(&pf, 0, sizeof(pf));
1694
1695 pf.apn = strdupReadString(p);
1696 pf.protocol = strdupReadString(p);
1697
1698 status = p.readInt32(&t);
1699 pf.authtype = (int) t;
1700
1701 pf.username = strdupReadString(p);
1702 pf.password = strdupReadString(p);
1703
1704 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001705 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1706 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001707 closeRequest;
1708 printRequest(pRI->token, pRI->pCI->requestNumber);
1709
1710 if (status != NO_ERROR) {
1711 goto invalid;
1712 }
Etan Cohend3652192014-06-20 08:28:44 -07001713 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001714
1715#ifdef MEMSET_FREED
1716 memsetString(pf.apn);
1717 memsetString(pf.protocol);
1718 memsetString(pf.username);
1719 memsetString(pf.password);
1720#endif
1721
1722 free(pf.apn);
1723 free(pf.protocol);
1724 free(pf.username);
1725 free(pf.password);
1726
1727#ifdef MEMSET_FREED
1728 memset(&pf, 0, sizeof(pf));
1729#endif
1730
1731 return;
1732invalid:
1733 invalidCommandBlock(pRI);
1734 return;
1735}
1736
Jake Hamby8a4a2332014-01-15 13:12:05 -08001737static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1738 RIL_NV_ReadItem nvri;
1739 int32_t t;
1740 status_t status;
1741
1742 memset(&nvri, 0, sizeof(nvri));
1743
1744 status = p.readInt32(&t);
1745 nvri.itemID = (RIL_NV_Item) t;
1746
1747 if (status != NO_ERROR) {
1748 goto invalid;
1749 }
1750
1751 startRequest;
1752 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1753 closeRequest;
1754
1755 printRequest(pRI->token, pRI->pCI->requestNumber);
1756
Etan Cohend3652192014-06-20 08:28:44 -07001757 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001758
1759#ifdef MEMSET_FREED
1760 memset(&nvri, 0, sizeof(nvri));
1761#endif
1762
1763 return;
1764
1765invalid:
1766 invalidCommandBlock(pRI);
1767 return;
1768}
1769
1770static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1771 RIL_NV_WriteItem nvwi;
1772 int32_t t;
1773 status_t status;
1774
1775 memset(&nvwi, 0, sizeof(nvwi));
1776
1777 status = p.readInt32(&t);
1778 nvwi.itemID = (RIL_NV_Item) t;
1779
1780 nvwi.value = strdupReadString(p);
1781
1782 if (status != NO_ERROR || nvwi.value == NULL) {
1783 goto invalid;
1784 }
1785
1786 startRequest;
1787 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1788 nvwi.value);
1789 closeRequest;
1790
1791 printRequest(pRI->token, pRI->pCI->requestNumber);
1792
Etan Cohend3652192014-06-20 08:28:44 -07001793 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001794
1795#ifdef MEMSET_FREED
1796 memsetString(nvwi.value);
1797#endif
1798
1799 free(nvwi.value);
1800
1801#ifdef MEMSET_FREED
1802 memset(&nvwi, 0, sizeof(nvwi));
1803#endif
1804
1805 return;
1806
1807invalid:
1808 invalidCommandBlock(pRI);
1809 return;
1810}
1811
1812
Etan Cohend3652192014-06-20 08:28:44 -07001813static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1814 RIL_SelectUiccSub uicc_sub;
1815 status_t status;
1816 int32_t t;
1817 memset(&uicc_sub, 0, sizeof(uicc_sub));
1818
1819 status = p.readInt32(&t);
1820 if (status != NO_ERROR) {
1821 goto invalid;
1822 }
1823 uicc_sub.slot = (int) t;
1824
1825 status = p.readInt32(&t);
1826 if (status != NO_ERROR) {
1827 goto invalid;
1828 }
1829 uicc_sub.app_index = (int) t;
1830
1831 status = p.readInt32(&t);
1832 if (status != NO_ERROR) {
1833 goto invalid;
1834 }
1835 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1836
1837 status = p.readInt32(&t);
1838 if (status != NO_ERROR) {
1839 goto invalid;
1840 }
1841 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1842
1843 startRequest;
1844 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1845 uicc_sub.act_status);
1846 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1847 uicc_sub.app_index, uicc_sub.act_status);
1848 closeRequest;
1849 printRequest(pRI->token, pRI->pCI->requestNumber);
1850
1851 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1852
1853#ifdef MEMSET_FREED
1854 memset(&uicc_sub, 0, sizeof(uicc_sub));
1855#endif
1856 return;
1857
1858invalid:
1859 invalidCommandBlock(pRI);
1860 return;
1861}
1862
Amit Mahajan90530a62014-07-01 15:54:08 -07001863static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1864{
1865 RIL_SimAuthentication pf;
1866 int32_t t;
1867 status_t status;
1868
1869 memset(&pf, 0, sizeof(pf));
1870
1871 status = p.readInt32(&t);
1872 pf.authContext = (int) t;
1873 pf.authData = strdupReadString(p);
1874 pf.aid = strdupReadString(p);
1875
1876 startRequest;
1877 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1878 closeRequest;
1879 printRequest(pRI->token, pRI->pCI->requestNumber);
1880
1881 if (status != NO_ERROR) {
1882 goto invalid;
1883 }
1884 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1885
1886#ifdef MEMSET_FREED
1887 memsetString(pf.authData);
1888 memsetString(pf.aid);
1889#endif
1890
1891 free(pf.authData);
1892 free(pf.aid);
1893
1894#ifdef MEMSET_FREED
1895 memset(&pf, 0, sizeof(pf));
1896#endif
1897
1898 return;
1899invalid:
1900 invalidCommandBlock(pRI);
1901 return;
1902}
1903
Amit Mahajanc796e222014-08-13 16:54:01 +00001904static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1905 int32_t t;
1906 status_t status;
1907 int32_t num;
1908
1909 status = p.readInt32(&num);
1910 if (status != NO_ERROR) {
1911 goto invalid;
1912 }
1913
1914 {
1915 RIL_DataProfileInfo dataProfiles[num];
1916 RIL_DataProfileInfo *dataProfilePtrs[num];
1917
1918 startRequest;
1919 for (int i = 0 ; i < num ; i++ ) {
1920 dataProfilePtrs[i] = &dataProfiles[i];
1921
1922 status = p.readInt32(&t);
1923 dataProfiles[i].profileId = (int) t;
1924
1925 dataProfiles[i].apn = strdupReadString(p);
1926 dataProfiles[i].protocol = strdupReadString(p);
1927 status = p.readInt32(&t);
1928 dataProfiles[i].authType = (int) t;
1929
1930 dataProfiles[i].user = strdupReadString(p);
1931 dataProfiles[i].password = strdupReadString(p);
1932
1933 status = p.readInt32(&t);
1934 dataProfiles[i].type = (int) t;
1935
1936 status = p.readInt32(&t);
1937 dataProfiles[i].maxConnsTime = (int) t;
1938 status = p.readInt32(&t);
1939 dataProfiles[i].maxConns = (int) t;
1940 status = p.readInt32(&t);
1941 dataProfiles[i].waitTime = (int) t;
1942
1943 status = p.readInt32(&t);
1944 dataProfiles[i].enabled = (int) t;
1945
1946 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1947 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1948 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1949 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1950 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1951 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1952 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1953 }
1954 closeRequest;
1955 printRequest(pRI->token, pRI->pCI->requestNumber);
1956
1957 if (status != NO_ERROR) {
1958 goto invalid;
1959 }
1960 CALL_ONREQUEST(pRI->pCI->requestNumber,
1961 dataProfilePtrs,
1962 num * sizeof(RIL_DataProfileInfo *),
1963 pRI, pRI->socket_id);
1964
1965#ifdef MEMSET_FREED
1966 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1967 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1968#endif
1969 }
1970
1971 return;
1972
1973invalid:
1974 invalidCommandBlock(pRI);
1975 return;
1976}
1977
Wink Saville8b4e4f72014-10-17 15:01:45 -07001978static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1979 RIL_RadioCapability rc;
1980 int32_t t;
1981 status_t status;
1982
1983 memset (&rc, 0, sizeof(RIL_RadioCapability));
1984
1985 status = p.readInt32(&t);
1986 rc.version = (int)t;
1987 if (status != NO_ERROR) {
1988 goto invalid;
1989 }
1990
1991 status = p.readInt32(&t);
1992 rc.session= (int)t;
1993 if (status != NO_ERROR) {
1994 goto invalid;
1995 }
1996
1997 status = p.readInt32(&t);
1998 rc.phase= (int)t;
1999 if (status != NO_ERROR) {
2000 goto invalid;
2001 }
2002
2003 status = p.readInt32(&t);
2004 rc.rat = (int)t;
2005 if (status != NO_ERROR) {
2006 goto invalid;
2007 }
2008
2009 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2010 if (status != NO_ERROR) {
2011 goto invalid;
2012 }
2013
2014 status = p.readInt32(&t);
2015 rc.status = (int)t;
2016
2017 if (status != NO_ERROR) {
2018 goto invalid;
2019 }
2020
2021 startRequest;
2022 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002023 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2024 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002025
2026 closeRequest;
2027 printRequest(pRI->token, pRI->pCI->requestNumber);
2028
2029 CALL_ONREQUEST(pRI->pCI->requestNumber,
2030 &rc,
2031 sizeof(RIL_RadioCapability),
2032 pRI, pRI->socket_id);
2033 return;
2034invalid:
2035 invalidCommandBlock(pRI);
2036 return;
2037}
2038
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002039static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002040blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002041 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002042 const uint8_t *toWrite;
2043
2044 toWrite = (const uint8_t *)buffer;
2045
2046 while (writeOffset < len) {
2047 ssize_t written;
2048 do {
2049 written = write (fd, toWrite + writeOffset,
2050 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302051 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002052
2053 if (written >= 0) {
2054 writeOffset += written;
2055 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002056 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002057 close(fd);
2058 return -1;
2059 }
2060 }
2061
2062 return 0;
2063}
2064
2065static int
Etan Cohend3652192014-06-20 08:28:44 -07002066sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2067 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002068 int ret;
2069 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002070 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002071
Etan Cohend3652192014-06-20 08:28:44 -07002072 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2073
2074#if (SIM_COUNT >= 2)
2075 if (socket_id == RIL_SOCKET_2) {
2076 fd = s_ril_param_socket2.fdCommand;
2077 writeMutexHook = &s_writeMutex_socket2;
2078 }
2079#if (SIM_COUNT >= 3)
2080 else if (socket_id == RIL_SOCKET_3) {
2081 fd = s_ril_param_socket3.fdCommand;
2082 writeMutexHook = &s_writeMutex_socket3;
2083 }
2084#endif
2085#if (SIM_COUNT >= 4)
2086 else if (socket_id == RIL_SOCKET_4) {
2087 fd = s_ril_param_socket4.fdCommand;
2088 writeMutexHook = &s_writeMutex_socket4;
2089 }
2090#endif
2091#endif
2092 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002093 return -1;
2094 }
2095
2096 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002097 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002098 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2099
2100 return -1;
2101 }
Wink Saville7f856802009-06-09 10:23:37 -07002102
Etan Cohend3652192014-06-20 08:28:44 -07002103 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002104
2105 header = htonl(dataSize);
2106
2107 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2108
2109 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002110 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002111 return ret;
2112 }
2113
Kennyee1fadc2009-08-13 00:45:53 +08002114 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002115
2116 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002117 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118 return ret;
2119 }
2120
Etan Cohend3652192014-06-20 08:28:44 -07002121 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002122
2123 return 0;
2124}
2125
2126static int
Etan Cohend3652192014-06-20 08:28:44 -07002127sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002128 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002129 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002130}
2131
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002132/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002133
2134static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002135responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136 int numInts;
2137
2138 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002139 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002140 return RIL_ERRNO_INVALID_RESPONSE;
2141 }
2142 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002143 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002144 (int)responselen, (int)sizeof(int));
2145 return RIL_ERRNO_INVALID_RESPONSE;
2146 }
2147
2148 int *p_int = (int *) response;
2149
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002150 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002151 p.writeInt32 (numInts);
2152
2153 /* each int*/
2154 startResponse;
2155 for (int i = 0 ; i < numInts ; i++) {
2156 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2157 p.writeInt32(p_int[i]);
2158 }
2159 removeLastChar;
2160 closeResponse;
2161
2162 return 0;
2163}
2164
Wink Saville43808972011-01-13 17:39:51 -08002165/** response is a char **, pointing to an array of char *'s
2166 The parcel will begin with the version */
2167static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2168 p.writeInt32(version);
2169 return responseStrings(p, response, responselen);
2170}
2171
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002172/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002173static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002174 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002175
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002176 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002177 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002178 return RIL_ERRNO_INVALID_RESPONSE;
2179 }
2180 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002181 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002182 (int)responselen, (int)sizeof(char *));
2183 return RIL_ERRNO_INVALID_RESPONSE;
2184 }
2185
2186 if (response == NULL) {
2187 p.writeInt32 (0);
2188 } else {
2189 char **p_cur = (char **) response;
2190
2191 numStrings = responselen / sizeof(char *);
2192 p.writeInt32 (numStrings);
2193
2194 /* each string*/
2195 startResponse;
2196 for (int i = 0 ; i < numStrings ; i++) {
2197 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2198 writeStringToParcel (p, p_cur[i]);
2199 }
2200 removeLastChar;
2201 closeResponse;
2202 }
2203 return 0;
2204}
2205
2206
2207/**
Wink Saville7f856802009-06-09 10:23:37 -07002208 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002209 * FIXME currently ignores responselen
2210 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002211static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002212 /* one string only */
2213 startResponse;
2214 appendPrintBuf("%s%s", printBuf, (char*)response);
2215 closeResponse;
2216
2217 writeStringToParcel(p, (const char *)response);
2218
2219 return 0;
2220}
2221
Wink Savillef4c4d362009-04-02 01:37:03 -07002222static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002223 startResponse;
2224 removeLastChar;
2225 return 0;
2226}
2227
Wink Savillef4c4d362009-04-02 01:37:03 -07002228static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002229 int num;
2230
2231 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002232 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002233 return RIL_ERRNO_INVALID_RESPONSE;
2234 }
2235
2236 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002237 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002238 (int)responselen, (int)sizeof (RIL_Call *));
2239 return RIL_ERRNO_INVALID_RESPONSE;
2240 }
2241
2242 startResponse;
2243 /* number of call info's */
2244 num = responselen / sizeof(RIL_Call *);
2245 p.writeInt32(num);
2246
2247 for (int i = 0 ; i < num ; i++) {
2248 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2249 /* each call info */
2250 p.writeInt32(p_cur->state);
2251 p.writeInt32(p_cur->index);
2252 p.writeInt32(p_cur->toa);
2253 p.writeInt32(p_cur->isMpty);
2254 p.writeInt32(p_cur->isMT);
2255 p.writeInt32(p_cur->als);
2256 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002257 p.writeInt32(p_cur->isVoicePrivacy);
2258 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002259 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002260 writeStringToParcel(p, p_cur->name);
2261 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002262 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002263 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2264 p.writeInt32(0); /* UUS Information is absent */
2265 } else {
2266 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2267 p.writeInt32(1); /* UUS Information is present */
2268 p.writeInt32(uusInfo->uusType);
2269 p.writeInt32(uusInfo->uusDcs);
2270 p.writeInt32(uusInfo->uusLength);
2271 p.write(uusInfo->uusData, uusInfo->uusLength);
2272 }
Wink Saville3d54e742009-05-18 18:00:44 -07002273 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002274 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002275 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002276 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002277 p_cur->toa);
2278 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2279 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002280 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002281 (p_cur->isMT)?"mt":"mo",
2282 p_cur->als,
2283 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002284 (p_cur->isVoicePrivacy)?"evp":"noevp");
2285 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2286 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002287 p_cur->number,
2288 p_cur->numberPresentation,
2289 p_cur->name,
2290 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002291 }
2292 removeLastChar;
2293 closeResponse;
2294
2295 return 0;
2296}
2297
Wink Savillef4c4d362009-04-02 01:37:03 -07002298static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002299 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002300 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002301 return RIL_ERRNO_INVALID_RESPONSE;
2302 }
2303
2304 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002305 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002306 (int)responselen, (int)sizeof (RIL_SMS_Response));
2307 return RIL_ERRNO_INVALID_RESPONSE;
2308 }
2309
2310 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2311
2312 p.writeInt32(p_cur->messageRef);
2313 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002314 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002315
2316 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002317 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2318 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002319 closeResponse;
2320
2321 return 0;
2322}
2323
Wink Savillec0114b32011-02-18 10:14:07 -08002324static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002325{
2326 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002327 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002328 return RIL_ERRNO_INVALID_RESPONSE;
2329 }
2330
Wink Savillec0114b32011-02-18 10:14:07 -08002331 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002332 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002333 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002334 return RIL_ERRNO_INVALID_RESPONSE;
2335 }
2336
Amit Mahajan52500162014-07-29 17:36:48 -07002337 // Write version
2338 p.writeInt32(4);
2339
Wink Savillec0114b32011-02-18 10:14:07 -08002340 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002341 p.writeInt32(num);
2342
Wink Savillec0114b32011-02-18 10:14:07 -08002343 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002344 startResponse;
2345 int i;
2346 for (i = 0; i < num; i++) {
2347 p.writeInt32(p_cur[i].cid);
2348 p.writeInt32(p_cur[i].active);
2349 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002350 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002351 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002352 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002353 p_cur[i].cid,
2354 (p_cur[i].active==0)?"down":"up",
2355 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002356 (char*)p_cur[i].address);
2357 }
2358 removeLastChar;
2359 closeResponse;
2360
2361 return 0;
2362}
2363
Etan Cohend3652192014-06-20 08:28:44 -07002364static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2365{
Amit Mahajan52500162014-07-29 17:36:48 -07002366 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002367 RLOGE("invalid response: NULL");
2368 return RIL_ERRNO_INVALID_RESPONSE;
2369 }
2370
2371 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002372 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002373 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2374 return RIL_ERRNO_INVALID_RESPONSE;
2375 }
2376
Amit Mahajan52500162014-07-29 17:36:48 -07002377 // Write version
2378 p.writeInt32(6);
2379
Etan Cohend3652192014-06-20 08:28:44 -07002380 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2381 p.writeInt32(num);
2382
2383 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2384 startResponse;
2385 int i;
2386 for (i = 0; i < num; i++) {
2387 p.writeInt32((int)p_cur[i].status);
2388 p.writeInt32(p_cur[i].suggestedRetryTime);
2389 p.writeInt32(p_cur[i].cid);
2390 p.writeInt32(p_cur[i].active);
2391 writeStringToParcel(p, p_cur[i].type);
2392 writeStringToParcel(p, p_cur[i].ifname);
2393 writeStringToParcel(p, p_cur[i].addresses);
2394 writeStringToParcel(p, p_cur[i].dnses);
2395 writeStringToParcel(p, p_cur[i].gateways);
2396 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2397 p_cur[i].status,
2398 p_cur[i].suggestedRetryTime,
2399 p_cur[i].cid,
2400 (p_cur[i].active==0)?"down":"up",
2401 (char*)p_cur[i].type,
2402 (char*)p_cur[i].ifname,
2403 (char*)p_cur[i].addresses,
2404 (char*)p_cur[i].dnses,
2405 (char*)p_cur[i].gateways);
2406 }
2407 removeLastChar;
2408 closeResponse;
2409
2410 return 0;
2411}
2412
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002413static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2414{
2415 if (response == NULL && responselen != 0) {
2416 RLOGE("invalid response: NULL");
2417 return RIL_ERRNO_INVALID_RESPONSE;
2418 }
2419
2420 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2421 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2422 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2423 return RIL_ERRNO_INVALID_RESPONSE;
2424 }
2425
2426 // Write version
2427 p.writeInt32(10);
2428
2429 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2430 p.writeInt32(num);
2431
2432 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2433 startResponse;
2434 int i;
2435 for (i = 0; i < num; i++) {
2436 p.writeInt32((int)p_cur[i].status);
2437 p.writeInt32(p_cur[i].suggestedRetryTime);
2438 p.writeInt32(p_cur[i].cid);
2439 p.writeInt32(p_cur[i].active);
2440 writeStringToParcel(p, p_cur[i].type);
2441 writeStringToParcel(p, p_cur[i].ifname);
2442 writeStringToParcel(p, p_cur[i].addresses);
2443 writeStringToParcel(p, p_cur[i].dnses);
2444 writeStringToParcel(p, p_cur[i].gateways);
2445 writeStringToParcel(p, p_cur[i].pcscf);
2446 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2447 p_cur[i].status,
2448 p_cur[i].suggestedRetryTime,
2449 p_cur[i].cid,
2450 (p_cur[i].active==0)?"down":"up",
2451 (char*)p_cur[i].type,
2452 (char*)p_cur[i].ifname,
2453 (char*)p_cur[i].addresses,
2454 (char*)p_cur[i].dnses,
2455 (char*)p_cur[i].gateways,
2456 (char*)p_cur[i].pcscf);
2457 }
2458 removeLastChar;
2459 closeResponse;
2460
2461 return 0;
2462}
2463
2464
Wink Saville43808972011-01-13 17:39:51 -08002465static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2466{
Wink Saville43808972011-01-13 17:39:51 -08002467 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002468 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002469 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002470 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2471 return responseDataCallListV6(p, response, responselen);
2472 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2473 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002474 } else {
2475 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002476 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002477 return RIL_ERRNO_INVALID_RESPONSE;
2478 }
2479
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002480 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2481 RLOGE("invalid response length %d expected multiple of %d",
2482 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002483 return RIL_ERRNO_INVALID_RESPONSE;
2484 }
2485
Amit Mahajan52500162014-07-29 17:36:48 -07002486 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002487 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002488
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002489 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002490 p.writeInt32(num);
2491
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002492 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002493 startResponse;
2494 int i;
2495 for (i = 0; i < num; i++) {
2496 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002497 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002498 p.writeInt32(p_cur[i].cid);
2499 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002500 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002501 writeStringToParcel(p, p_cur[i].ifname);
2502 writeStringToParcel(p, p_cur[i].addresses);
2503 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002504 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002505 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002506 p.writeInt32(p_cur[i].mtu);
2507 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002508 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002509 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002510 p_cur[i].cid,
2511 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002512 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002513 (char*)p_cur[i].ifname,
2514 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002515 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002516 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002517 (char*)p_cur[i].pcscf,
2518 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002519 }
2520 removeLastChar;
2521 closeResponse;
2522 }
2523
2524 return 0;
2525}
2526
2527static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2528{
2529 if (s_callbacks.version < 5) {
2530 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2531 } else {
2532 return responseDataCallList(p, response, responselen);
2533 }
2534}
2535
Wink Savillef4c4d362009-04-02 01:37:03 -07002536static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002537 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002538 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002539 return RIL_ERRNO_INVALID_RESPONSE;
2540 }
2541
2542 // The java code reads -1 size as null byte array
2543 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002544 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002545 } else {
2546 p.writeInt32(responselen);
2547 p.write(response, responselen);
2548 }
2549
2550 return 0;
2551}
2552
2553
Wink Savillef4c4d362009-04-02 01:37:03 -07002554static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002555 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002556 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002557 return RIL_ERRNO_INVALID_RESPONSE;
2558 }
2559
2560 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002561 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002562 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2563 return RIL_ERRNO_INVALID_RESPONSE;
2564 }
2565
2566 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2567 p.writeInt32(p_cur->sw1);
2568 p.writeInt32(p_cur->sw2);
2569 writeStringToParcel(p, p_cur->simResponse);
2570
2571 startResponse;
2572 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2573 (char*)p_cur->simResponse);
2574 closeResponse;
2575
2576
2577 return 0;
2578}
2579
Wink Savillef4c4d362009-04-02 01:37:03 -07002580static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002581 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002582
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002583 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002584 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002585 return RIL_ERRNO_INVALID_RESPONSE;
2586 }
2587
2588 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002589 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002590 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2591 return RIL_ERRNO_INVALID_RESPONSE;
2592 }
2593
2594 /* number of call info's */
2595 num = responselen / sizeof(RIL_CallForwardInfo *);
2596 p.writeInt32(num);
2597
2598 startResponse;
2599 for (int i = 0 ; i < num ; i++) {
2600 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2601
2602 p.writeInt32(p_cur->status);
2603 p.writeInt32(p_cur->reason);
2604 p.writeInt32(p_cur->serviceClass);
2605 p.writeInt32(p_cur->toa);
2606 writeStringToParcel(p, p_cur->number);
2607 p.writeInt32(p_cur->timeSeconds);
2608 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2609 (p_cur->status==1)?"enable":"disable",
2610 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2611 (char*)p_cur->number,
2612 p_cur->timeSeconds);
2613 }
2614 removeLastChar;
2615 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002616
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002617 return 0;
2618}
2619
Wink Savillef4c4d362009-04-02 01:37:03 -07002620static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002621 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002622 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002623 return RIL_ERRNO_INVALID_RESPONSE;
2624 }
2625
2626 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002627 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002628 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2629 return RIL_ERRNO_INVALID_RESPONSE;
2630 }
2631
2632 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2633 p.writeInt32(p_cur->notificationType);
2634 p.writeInt32(p_cur->code);
2635 p.writeInt32(p_cur->index);
2636 p.writeInt32(p_cur->type);
2637 writeStringToParcel(p, p_cur->number);
2638
2639 startResponse;
2640 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2641 (p_cur->notificationType==0)?"mo":"mt",
2642 p_cur->code, p_cur->index, p_cur->type,
2643 (char*)p_cur->number);
2644 closeResponse;
2645
2646 return 0;
2647}
2648
Wink Saville3d54e742009-05-18 18:00:44 -07002649static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002650 int num;
2651
2652 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002653 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002654 return RIL_ERRNO_INVALID_RESPONSE;
2655 }
2656
2657 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002658 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002659 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2660 return RIL_ERRNO_INVALID_RESPONSE;
2661 }
2662
2663 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002664 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002665 num = responselen / sizeof(RIL_NeighboringCell *);
2666 p.writeInt32(num);
2667
2668 for (int i = 0 ; i < num ; i++) {
2669 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2670
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002671 p.writeInt32(p_cur->rssi);
2672 writeStringToParcel (p, p_cur->cid);
2673
2674 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2675 p_cur->cid, p_cur->rssi);
2676 }
2677 removeLastChar;
2678 closeResponse;
2679
2680 return 0;
2681}
2682
Wink Saville3d54e742009-05-18 18:00:44 -07002683/**
2684 * Marshall the signalInfoRecord into the parcel if it exists.
2685 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002686static void marshallSignalInfoRecord(Parcel &p,
2687 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002688 p.writeInt32(p_signalInfoRecord.isPresent);
2689 p.writeInt32(p_signalInfoRecord.signalType);
2690 p.writeInt32(p_signalInfoRecord.alertPitch);
2691 p.writeInt32(p_signalInfoRecord.signal);
2692}
2693
Wink Savillea592eeb2009-05-22 13:26:36 -07002694static int responseCdmaInformationRecords(Parcel &p,
2695 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002696 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002697 char* string8 = NULL;
2698 int buffer_lenght;
2699 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002700
2701 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002702 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002703 return RIL_ERRNO_INVALID_RESPONSE;
2704 }
2705
Wink Savillea592eeb2009-05-22 13:26:36 -07002706 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002707 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002708 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002709 return RIL_ERRNO_INVALID_RESPONSE;
2710 }
2711
Wink Savillea592eeb2009-05-22 13:26:36 -07002712 RIL_CDMA_InformationRecords *p_cur =
2713 (RIL_CDMA_InformationRecords *) response;
2714 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002715
2716 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002717 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002718
Wink Savillea592eeb2009-05-22 13:26:36 -07002719 for (int i = 0 ; i < num ; i++) {
2720 infoRec = &p_cur->infoRec[i];
2721 p.writeInt32(infoRec->name);
2722 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002723 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002724 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2725 if (infoRec->rec.display.alpha_len >
2726 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002727 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002728 expected not more than %d\n",
2729 (int)infoRec->rec.display.alpha_len,
2730 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2731 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002732 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002733 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2734 * sizeof(char) );
2735 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2736 string8[i] = infoRec->rec.display.alpha_buf[i];
2737 }
Wink Saville43808972011-01-13 17:39:51 -08002738 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002739 writeStringToParcel(p, (const char*)string8);
2740 free(string8);
2741 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002742 break;
2743 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002744 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002745 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002746 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002747 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002748 expected not more than %d\n",
2749 (int)infoRec->rec.number.len,
2750 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2751 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002752 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002753 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2754 * sizeof(char) );
2755 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2756 string8[i] = infoRec->rec.number.buf[i];
2757 }
Wink Saville43808972011-01-13 17:39:51 -08002758 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002759 writeStringToParcel(p, (const char*)string8);
2760 free(string8);
2761 string8 = NULL;
2762 p.writeInt32(infoRec->rec.number.number_type);
2763 p.writeInt32(infoRec->rec.number.number_plan);
2764 p.writeInt32(infoRec->rec.number.pi);
2765 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002766 break;
2767 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002768 p.writeInt32(infoRec->rec.signal.isPresent);
2769 p.writeInt32(infoRec->rec.signal.signalType);
2770 p.writeInt32(infoRec->rec.signal.alertPitch);
2771 p.writeInt32(infoRec->rec.signal.signal);
2772
2773 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2774 alertPitch=%X, signal=%X, ",
2775 printBuf, (int)infoRec->rec.signal.isPresent,
2776 (int)infoRec->rec.signal.signalType,
2777 (int)infoRec->rec.signal.alertPitch,
2778 (int)infoRec->rec.signal.signal);
2779 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002780 break;
2781 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002782 if (infoRec->rec.redir.redirectingNumber.len >
2783 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002784 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002785 expected not more than %d\n",
2786 (int)infoRec->rec.redir.redirectingNumber.len,
2787 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2788 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002789 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002790 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2791 .len + 1) * sizeof(char) );
2792 for (int i = 0;
2793 i < infoRec->rec.redir.redirectingNumber.len;
2794 i++) {
2795 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2796 }
Wink Saville43808972011-01-13 17:39:51 -08002797 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002798 writeStringToParcel(p, (const char*)string8);
2799 free(string8);
2800 string8 = NULL;
2801 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2802 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2803 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2804 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2805 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002806 break;
2807 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002808 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2809 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2810 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2811 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2812
2813 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2814 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2815 lineCtrlPowerDenial=%d, ", printBuf,
2816 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2817 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2818 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2819 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2820 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002821 break;
2822 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002823 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002824
Wink Savillea592eeb2009-05-22 13:26:36 -07002825 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2826 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002827 break;
2828 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002829 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2830 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2831
2832 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2833 infoRec->rec.audioCtrl.upLink,
2834 infoRec->rec.audioCtrl.downLink);
2835 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002836 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002837 case RIL_CDMA_T53_RELEASE_INFO_REC:
2838 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002839 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002840 return RIL_ERRNO_INVALID_RESPONSE;
2841 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002842 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002843 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002844 }
2845 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002846 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002847
Wink Savillea592eeb2009-05-22 13:26:36 -07002848 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002849}
2850
Wink Savillea592eeb2009-05-22 13:26:36 -07002851static int responseRilSignalStrength(Parcel &p,
2852 void *response, size_t responselen) {
2853 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002854 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002855 return RIL_ERRNO_INVALID_RESPONSE;
2856 }
2857
Wink Savillec0114b32011-02-18 10:14:07 -08002858 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002859 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002860
Wink Saville3d54e742009-05-18 18:00:44 -07002861 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2862 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2863 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2864 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2865 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2866 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2867 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002868 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002869 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002870 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002871 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002872 if (s_callbacks.version <= 6) {
2873 // signalStrength: -1 -> 99
2874 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2875 p_cur->LTE_SignalStrength.signalStrength = 99;
2876 }
2877 // rsrp: -1 -> INT_MAX all other negative value to positive.
2878 // So remap here
2879 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2880 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2881 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2882 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2883 }
2884 // rsrq: -1 -> INT_MAX
2885 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2886 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2887 }
2888 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002889
Wink Saville18e4ab12013-04-07 17:31:04 -07002890 // cqi: -1 -> INT_MAX
2891 if (p_cur->LTE_SignalStrength.cqi == -1) {
2892 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2893 }
2894 }
2895 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002896 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2897 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2898 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2899 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002900 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2901 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2902 } else {
2903 p.writeInt32(INT_MAX);
2904 }
Wink Savillec0114b32011-02-18 10:14:07 -08002905 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002906 p.writeInt32(99);
2907 p.writeInt32(INT_MAX);
2908 p.writeInt32(INT_MAX);
2909 p.writeInt32(INT_MAX);
2910 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002911 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002912 }
johnwangfdf825f2009-05-22 15:50:34 -07002913
2914 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002915 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002916 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2917 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2918 EVDO_SS.signalNoiseRatio=%d,\
2919 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002920 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002921 printBuf,
2922 p_cur->GW_SignalStrength.signalStrength,
2923 p_cur->GW_SignalStrength.bitErrorRate,
2924 p_cur->CDMA_SignalStrength.dbm,
2925 p_cur->CDMA_SignalStrength.ecio,
2926 p_cur->EVDO_SignalStrength.dbm,
2927 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002928 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2929 p_cur->LTE_SignalStrength.signalStrength,
2930 p_cur->LTE_SignalStrength.rsrp,
2931 p_cur->LTE_SignalStrength.rsrq,
2932 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002933 p_cur->LTE_SignalStrength.cqi,
2934 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002935 closeResponse;
2936
Wink Saville3d54e742009-05-18 18:00:44 -07002937 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002938 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002939 return RIL_ERRNO_INVALID_RESPONSE;
2940 }
2941
Wink Saville3d54e742009-05-18 18:00:44 -07002942 return 0;
2943}
2944
2945static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2946 if ((response == NULL) || (responselen == 0)) {
2947 return responseVoid(p, response, responselen);
2948 } else {
2949 return responseCdmaSignalInfoRecord(p, response, responselen);
2950 }
2951}
2952
2953static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2954 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002955 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002956 return RIL_ERRNO_INVALID_RESPONSE;
2957 }
2958
2959 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002960 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002961 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2962 return RIL_ERRNO_INVALID_RESPONSE;
2963 }
2964
2965 startResponse;
2966
2967 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2968 marshallSignalInfoRecord(p, *p_cur);
2969
2970 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2971 signal=%d]",
2972 printBuf,
2973 p_cur->isPresent,
2974 p_cur->signalType,
2975 p_cur->alertPitch,
2976 p_cur->signal);
2977
2978 closeResponse;
2979 return 0;
2980}
2981
Wink Savillea592eeb2009-05-22 13:26:36 -07002982static int responseCdmaCallWaiting(Parcel &p, void *response,
2983 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002984 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002985 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002986 return RIL_ERRNO_INVALID_RESPONSE;
2987 }
2988
Wink Savillec0114b32011-02-18 10:14:07 -08002989 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002990 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002991 }
2992
2993 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2994
2995 writeStringToParcel(p, p_cur->number);
2996 p.writeInt32(p_cur->numberPresentation);
2997 writeStringToParcel(p, p_cur->name);
2998 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2999
3000 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3001 p.writeInt32(p_cur->number_type);
3002 p.writeInt32(p_cur->number_plan);
3003 } else {
3004 p.writeInt32(0);
3005 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003006 }
3007
3008 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003009 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3010 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003011 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003012 printBuf,
3013 p_cur->number,
3014 p_cur->numberPresentation,
3015 p_cur->name,
3016 p_cur->signalInfoRecord.isPresent,
3017 p_cur->signalInfoRecord.signalType,
3018 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003019 p_cur->signalInfoRecord.signal,
3020 p_cur->number_type,
3021 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003022 closeResponse;
3023
3024 return 0;
3025}
3026
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003027static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3028 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003029 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003030 return RIL_ERRNO_INVALID_RESPONSE;
3031 }
3032
3033 startResponse;
3034 if (s_callbacks.version == 7) {
3035 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3036 p.writeInt32(p_cur->result);
3037 p.writeInt32(p_cur->ef_id);
3038 writeStringToParcel(p, p_cur->aid);
3039
3040 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3041 printBuf,
3042 p_cur->result,
3043 p_cur->ef_id,
3044 p_cur->aid);
3045 } else {
3046 int *p_cur = ((int *) response);
3047 p.writeInt32(p_cur[0]);
3048 p.writeInt32(p_cur[1]);
3049 writeStringToParcel(p, NULL);
3050
3051 appendPrintBuf("%sresult=%d, ef_id=%d",
3052 printBuf,
3053 p_cur[0],
3054 p_cur[1]);
3055 }
3056 closeResponse;
3057
3058 return 0;
3059}
3060
Wink Saville8a9e0212013-04-09 12:11:38 -07003061static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3062{
3063 if (response == NULL && responselen != 0) {
3064 RLOGE("invalid response: NULL");
3065 return RIL_ERRNO_INVALID_RESPONSE;
3066 }
3067
3068 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003069 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003070 (int)responselen, (int)sizeof(RIL_CellInfo));
3071 return RIL_ERRNO_INVALID_RESPONSE;
3072 }
3073
3074 int num = responselen / sizeof(RIL_CellInfo);
3075 p.writeInt32(num);
3076
3077 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3078 startResponse;
3079 int i;
3080 for (i = 0; i < num; i++) {
3081 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3082 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3083 p.writeInt32((int)p_cur->cellInfoType);
3084 p.writeInt32(p_cur->registered);
3085 p.writeInt32(p_cur->timeStampType);
3086 p.writeInt64(p_cur->timeStamp);
3087 switch(p_cur->cellInfoType) {
3088 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003089 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003090 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3091 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3092 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003093 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3094 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003095 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3096 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3097
3098 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3099 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3100 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3101 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003102 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3103 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3104 break;
3105 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003106 case RIL_CELL_INFO_TYPE_WCDMA: {
3107 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3108 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3109 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3110 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3111 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3112 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3113 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3114 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3115 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3116
3117 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3118 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3119 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3120 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3121 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3122 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3123 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3124 break;
3125 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003126 case RIL_CELL_INFO_TYPE_CDMA: {
3127 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3128 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3129 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3130 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3131 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3132 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3133
3134 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3135 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3136 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3137 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3138 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3139
3140 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3141 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3142 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3143 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3144 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3145 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3146
3147 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3148 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3149 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3150 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3151 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3152 break;
3153 }
3154 case RIL_CELL_INFO_TYPE_LTE: {
3155 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3156 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3157 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3158 p_cur->CellInfo.lte.cellIdentityLte.ci,
3159 p_cur->CellInfo.lte.cellIdentityLte.pci,
3160 p_cur->CellInfo.lte.cellIdentityLte.tac);
3161
3162 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3163 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3164 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3165 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3166 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3167
3168 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3169 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3170 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3171 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3172 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3173 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3174 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3175 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3176 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3177 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3178 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3179 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3180 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3181 break;
3182 }
Etan Cohend3652192014-06-20 08:28:44 -07003183 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3184 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3185 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3186 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3187 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3188 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3189 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3190 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3191 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3192
3193 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3194 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3195 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3196 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3197 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3198 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3199 break;
3200 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003201 }
3202 p_cur += 1;
3203 }
3204 removeLastChar;
3205 closeResponse;
3206
3207 return 0;
3208}
3209
Etan Cohend3652192014-06-20 08:28:44 -07003210static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3211{
3212 if (response == NULL && responselen != 0) {
3213 RLOGE("invalid response: NULL");
3214 return RIL_ERRNO_INVALID_RESPONSE;
3215 }
3216
3217 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003218 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003219 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3220 return RIL_ERRNO_INVALID_RESPONSE;
3221 }
3222
3223 int num = responselen / sizeof(RIL_HardwareConfig);
3224 int i;
3225 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3226
3227 p.writeInt32(num);
3228
3229 startResponse;
3230 for (i = 0; i < num; i++) {
3231 switch (p_cur[i].type) {
3232 case RIL_HARDWARE_CONFIG_MODEM: {
3233 writeStringToParcel(p, p_cur[i].uuid);
3234 p.writeInt32((int)p_cur[i].state);
3235 p.writeInt32(p_cur[i].cfg.modem.rat);
3236 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3237 p.writeInt32(p_cur[i].cfg.modem.maxData);
3238 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3239
3240 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3241 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3242 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3243 break;
3244 }
3245 case RIL_HARDWARE_CONFIG_SIM: {
3246 writeStringToParcel(p, p_cur[i].uuid);
3247 p.writeInt32((int)p_cur[i].state);
3248 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3249
3250 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3251 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3252 break;
3253 }
3254 }
3255 }
3256 removeLastChar;
3257 closeResponse;
3258 return 0;
3259}
3260
Wink Saville8b4e4f72014-10-17 15:01:45 -07003261static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3262 if (response == NULL) {
3263 RLOGE("invalid response: NULL");
3264 return RIL_ERRNO_INVALID_RESPONSE;
3265 }
3266
3267 if (responselen != sizeof (RIL_RadioCapability) ) {
3268 RLOGE("invalid response length was %d expected %d",
3269 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3270 return RIL_ERRNO_INVALID_RESPONSE;
3271 }
3272
3273 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3274 p.writeInt32(p_cur->version);
3275 p.writeInt32(p_cur->session);
3276 p.writeInt32(p_cur->phase);
3277 p.writeInt32(p_cur->rat);
3278 writeStringToParcel(p, p_cur->logicalModemUuid);
3279 p.writeInt32(p_cur->status);
3280
3281 startResponse;
3282 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003283 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003284 printBuf,
3285 p_cur->version,
3286 p_cur->session,
3287 p_cur->phase,
3288 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003289 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003290 p_cur->status);
3291 closeResponse;
3292 return 0;
3293}
3294
Amit Mahajan54563d32014-11-22 00:54:49 +00003295static int responseSSData(Parcel &p, void *response, size_t responselen) {
3296 RLOGD("In responseSSData");
3297 int num;
3298
3299 if (response == NULL && responselen != 0) {
3300 RLOGE("invalid response length was %d expected %d",
3301 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3302 return RIL_ERRNO_INVALID_RESPONSE;
3303 }
3304
3305 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3306 RLOGE("invalid response length %d, expected %d",
3307 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3308 return RIL_ERRNO_INVALID_RESPONSE;
3309 }
3310
3311 startResponse;
3312 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3313 p.writeInt32(p_cur->serviceType);
3314 p.writeInt32(p_cur->requestType);
3315 p.writeInt32(p_cur->teleserviceType);
3316 p.writeInt32(p_cur->serviceClass);
3317 p.writeInt32(p_cur->result);
3318
3319 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3320 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3321 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3322 RLOGE("numValidIndexes is greater than max value %d, "
3323 "truncating it to max value", NUM_SERVICE_CLASSES);
3324 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3325 }
3326 /* number of call info's */
3327 p.writeInt32(p_cur->cfData.numValidIndexes);
3328
3329 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3330 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3331
3332 p.writeInt32(cf.status);
3333 p.writeInt32(cf.reason);
3334 p.writeInt32(cf.serviceClass);
3335 p.writeInt32(cf.toa);
3336 writeStringToParcel(p, cf.number);
3337 p.writeInt32(cf.timeSeconds);
3338 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3339 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3340 (char*)cf.number, cf.timeSeconds);
3341 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3342 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3343 }
3344 } else {
3345 p.writeInt32 (SS_INFO_MAX);
3346
3347 /* each int*/
3348 for (int i = 0; i < SS_INFO_MAX; i++) {
3349 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3350 RLOGD("Data: %d",p_cur->ssInfo[i]);
3351 p.writeInt32(p_cur->ssInfo[i]);
3352 }
3353 }
3354 removeLastChar;
3355 closeResponse;
3356
3357 return 0;
3358}
3359
3360static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3361 if ((reqType == SS_INTERROGATION) &&
3362 (serType == SS_CFU ||
3363 serType == SS_CF_BUSY ||
3364 serType == SS_CF_NO_REPLY ||
3365 serType == SS_CF_NOT_REACHABLE ||
3366 serType == SS_CF_ALL ||
3367 serType == SS_CF_ALL_CONDITIONAL)) {
3368 return true;
3369 }
3370 return false;
3371}
3372
Wink Saville3d54e742009-05-18 18:00:44 -07003373static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003374 int ret;
3375 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3376 /* trigger event loop to wakeup. No reason to do this,
3377 * if we're in the event loop thread */
3378 do {
3379 ret = write (s_fdWakeupWrite, " ", 1);
3380 } while (ret < 0 && errno == EINTR);
3381 }
3382}
3383
Wink Saville3d54e742009-05-18 18:00:44 -07003384static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003385 ril_event_add(ev);
3386 triggerEvLoop();
3387}
3388
Wink Savillefd729372011-02-22 16:19:39 -08003389static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3390 p.writeInt32(num_apps);
3391 startResponse;
3392 for (int i = 0; i < num_apps; i++) {
3393 p.writeInt32(appStatus[i].app_type);
3394 p.writeInt32(appStatus[i].app_state);
3395 p.writeInt32(appStatus[i].perso_substate);
3396 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3397 writeStringToParcel(p, (const char*)
3398 (appStatus[i].app_label_ptr));
3399 p.writeInt32(appStatus[i].pin1_replaced);
3400 p.writeInt32(appStatus[i].pin1);
3401 p.writeInt32(appStatus[i].pin2);
3402 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3403 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3404 printBuf,
3405 appStatus[i].app_type,
3406 appStatus[i].app_state,
3407 appStatus[i].perso_substate,
3408 appStatus[i].aid_ptr,
3409 appStatus[i].app_label_ptr,
3410 appStatus[i].pin1_replaced,
3411 appStatus[i].pin1,
3412 appStatus[i].pin2);
3413 }
3414 closeResponse;
3415}
3416
Wink Savillef4c4d362009-04-02 01:37:03 -07003417static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3418 int i;
3419
3420 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003421 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003422 return RIL_ERRNO_INVALID_RESPONSE;
3423 }
3424
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003425 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003426 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003427
Wink Savillefd729372011-02-22 16:19:39 -08003428 p.writeInt32(p_cur->card_state);
3429 p.writeInt32(p_cur->universal_pin_state);
3430 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3431 p.writeInt32(p_cur->cdma_subscription_app_index);
3432 p.writeInt32(p_cur->ims_subscription_app_index);
3433
3434 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003435 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003436 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3437
3438 p.writeInt32(p_cur->card_state);
3439 p.writeInt32(p_cur->universal_pin_state);
3440 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3441 p.writeInt32(p_cur->cdma_subscription_app_index);
3442 p.writeInt32(-1);
3443
3444 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003445 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003446 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003447 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003448 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003449
3450 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003451}
Wink Savillef4c4d362009-04-02 01:37:03 -07003452
Wink Savillea592eeb2009-05-22 13:26:36 -07003453static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3454 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003455 p.writeInt32(num);
3456
Wink Savillef4c4d362009-04-02 01:37:03 -07003457 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003458 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3459 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3460 for (int i = 0; i < num; i++) {
3461 p.writeInt32(p_cur[i]->fromServiceId);
3462 p.writeInt32(p_cur[i]->toServiceId);
3463 p.writeInt32(p_cur[i]->fromCodeScheme);
3464 p.writeInt32(p_cur[i]->toCodeScheme);
3465 p.writeInt32(p_cur[i]->selected);
3466
3467 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3468 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3469 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3470 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3471 p_cur[i]->selected);
3472 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003473 closeResponse;
3474
3475 return 0;
3476}
3477
Wink Savillea592eeb2009-05-22 13:26:36 -07003478static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3479 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3480 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003481
Wink Savillea592eeb2009-05-22 13:26:36 -07003482 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3483 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003484
3485 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003486 for (int i = 0 ; i < num ; i++ ) {
3487 p.writeInt32(p_cur[i]->service_category);
3488 p.writeInt32(p_cur[i]->language);
3489 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003490
Wink Savillea592eeb2009-05-22 13:26:36 -07003491 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3492 selected =%d], ",
3493 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3494 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003495 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003496 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003497
Wink Savillef4c4d362009-04-02 01:37:03 -07003498 return 0;
3499}
3500
3501static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3502 int num;
3503 int digitCount;
3504 int digitLimit;
3505 uint8_t uct;
3506 void* dest;
3507
Wink Saville8eb2a122012-11-19 16:05:13 -08003508 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003509
Wink Savillef4c4d362009-04-02 01:37:03 -07003510 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003511 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003512 return RIL_ERRNO_INVALID_RESPONSE;
3513 }
3514
Wink Savillef5903df2009-04-24 11:54:14 -07003515 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003516 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003517 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003518 return RIL_ERRNO_INVALID_RESPONSE;
3519 }
3520
3521 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3522 p.writeInt32(p_cur->uTeleserviceID);
3523 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3524 p.writeInt32(p_cur->uServicecategory);
3525 p.writeInt32(p_cur->sAddress.digit_mode);
3526 p.writeInt32(p_cur->sAddress.number_mode);
3527 p.writeInt32(p_cur->sAddress.number_type);
3528 p.writeInt32(p_cur->sAddress.number_plan);
3529 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3530 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3531 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3532 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3533 }
3534
3535 p.writeInt32(p_cur->sSubAddress.subaddressType);
3536 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3537 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3538 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3539 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3540 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3541 }
3542
3543 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3544 p.writeInt32(p_cur->uBearerDataLen);
3545 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3546 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3547 }
3548
3549 startResponse;
3550 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003551 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003552 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3553 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3554 closeResponse;
3555
3556 return 0;
3557}
3558
Wink Savillec29360a2014-07-13 05:17:28 -07003559static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3560{
3561 int num = responselen / sizeof(RIL_DcRtInfo);
3562 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003563 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003564 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3565 return RIL_ERRNO_INVALID_RESPONSE;
3566 }
3567
3568 startResponse;
3569 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3570 p.writeInt64(pDcRtInfo->time);
3571 p.writeInt32(pDcRtInfo->powerState);
3572 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3573 pDcRtInfo->time,
3574 pDcRtInfo->powerState);
3575 closeResponse;
3576
3577 return 0;
3578}
3579
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003580/**
3581 * A write on the wakeup fd is done just to pop us out of select()
3582 * We empty the buffer here and then ril_event will reset the timers on the
3583 * way back down
3584 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003585static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003586 char buff[16];
3587 int ret;
3588
Wink Saville8eb2a122012-11-19 16:05:13 -08003589 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003590
3591 /* empty our wakeup socket out */
3592 do {
3593 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003594 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003595}
3596
Etan Cohend3652192014-06-20 08:28:44 -07003597static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003598 int ret;
3599 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003600 /* Hook for current context
3601 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3602 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3603 /* pendingRequestsHook refer to &s_pendingRequests */
3604 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003605
Etan Cohend3652192014-06-20 08:28:44 -07003606#if (SIM_COUNT >= 2)
3607 if (socket_id == RIL_SOCKET_2) {
3608 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3609 pendingRequestsHook = &s_pendingRequests_socket2;
3610 }
3611#if (SIM_COUNT >= 3)
3612 else if (socket_id == RIL_SOCKET_3) {
3613 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3614 pendingRequestsHook = &s_pendingRequests_socket3;
3615 }
3616#endif
3617#if (SIM_COUNT >= 4)
3618 else if (socket_id == RIL_SOCKET_4) {
3619 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3620 pendingRequestsHook = &s_pendingRequests_socket4;
3621 }
3622#endif
3623#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003624 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003625 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003626 assert (ret == 0);
3627
Etan Cohend3652192014-06-20 08:28:44 -07003628 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003629
Etan Cohend3652192014-06-20 08:28:44 -07003630 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003631 ; p_cur != NULL
3632 ; p_cur = p_cur->p_next
3633 ) {
3634 p_cur->cancelled = 1;
3635 }
3636
Etan Cohend3652192014-06-20 08:28:44 -07003637 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003638 assert (ret == 0);
3639}
3640
Wink Savillef4c4d362009-04-02 01:37:03 -07003641static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003642 RecordStream *p_rs;
3643 void *p_record;
3644 size_t recordlen;
3645 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003646 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003647
Etan Cohend3652192014-06-20 08:28:44 -07003648 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003649
Etan Cohend3652192014-06-20 08:28:44 -07003650 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003651
3652 for (;;) {
3653 /* loop until EAGAIN/EINTR, end of stream, or other error */
3654 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3655
3656 if (ret == 0 && p_record == NULL) {
3657 /* end-of-stream */
3658 break;
3659 } else if (ret < 0) {
3660 break;
3661 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003662 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003663 }
3664 }
3665
3666 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3667 /* fatal error or end-of-stream */
3668 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003669 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003670 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003671 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672 }
Wink Saville7f856802009-06-09 10:23:37 -07003673
Etan Cohend3652192014-06-20 08:28:44 -07003674 close(fd);
3675 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003676
Etan Cohend3652192014-06-20 08:28:44 -07003677 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003678
3679 record_stream_free(p_rs);
3680
3681 /* start listening for new connections again */
3682 rilEventAddWakeup(&s_listen_event);
3683
Etan Cohend3652192014-06-20 08:28:44 -07003684 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003685 }
3686}
3687
3688
Etan Cohend3652192014-06-20 08:28:44 -07003689static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003690 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003691 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003692 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3693 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003694
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003695 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003696 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3697 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003698
3699 // Send last NITZ time data, in case it was missed
3700 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003701 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003702
3703 free(s_lastNITZTimeData);
3704 s_lastNITZTimeData = NULL;
3705 }
3706
3707 // Get version string
3708 if (s_callbacks.getVersion != NULL) {
3709 const char *version;
3710 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003711 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003712
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003713 property_set(PROPERTY_RIL_IMPL, version);
3714 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003715 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003716 property_set(PROPERTY_RIL_IMPL, "unavailable");
3717 }
3718
3719}
3720
Wink Savillef4c4d362009-04-02 01:37:03 -07003721static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003722 int ret;
3723 int err;
3724 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003725 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003726 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003727 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003728
3729 struct sockaddr_un peeraddr;
3730 socklen_t socklen = sizeof (peeraddr);
3731
3732 struct ucred creds;
3733 socklen_t szCreds = sizeof(creds);
3734
3735 struct passwd *pwd = NULL;
3736
Etan Cohend3652192014-06-20 08:28:44 -07003737 assert (*p_info->fdCommand < 0);
3738 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003739
Etan Cohend3652192014-06-20 08:28:44 -07003740 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003741
Etan Cohend3652192014-06-20 08:28:44 -07003742 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003743 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003744 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003745 rilEventAddWakeup(p_info->listen_event);
3746 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003747 }
3748
3749 /* check the credential of the other side and only accept socket from
3750 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003751 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003752 errno = 0;
3753 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003754
Etan Cohend3652192014-06-20 08:28:44 -07003755 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003756
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003757 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003758 errno = 0;
3759 pwd = getpwuid(creds.uid);
3760 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003761 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003762 is_phone_socket = 1;
3763 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003764 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003765 }
3766 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003767 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003768 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003769 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003770 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003771 }
3772
Etan Cohend3652192014-06-20 08:28:44 -07003773 if (!is_phone_socket) {
3774 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003775
Etan Cohend3652192014-06-20 08:28:44 -07003776 close(fdCommand);
3777 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003778
Etan Cohend3652192014-06-20 08:28:44 -07003779 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003780
3781 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003782 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003783
3784 return;
3785 }
3786
Etan Cohend3652192014-06-20 08:28:44 -07003787 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003788
3789 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003790 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003791 }
3792
Etan Cohend3652192014-06-20 08:28:44 -07003793 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003794
Etan Cohend3652192014-06-20 08:28:44 -07003795 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003796
Etan Cohend3652192014-06-20 08:28:44 -07003797 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003798
Etan Cohend3652192014-06-20 08:28:44 -07003799 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003800
Etan Cohend3652192014-06-20 08:28:44 -07003801 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3802 p_info->processCommandsCallback, p_info);
3803
3804 rilEventAddWakeup (p_info->commands_event);
3805
3806 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003807}
3808
3809static void freeDebugCallbackArgs(int number, char **args) {
3810 for (int i = 0; i < number; i++) {
3811 if (args[i] != NULL) {
3812 free(args[i]);
3813 }
3814 }
3815 free(args);
3816}
3817
Wink Savillef4c4d362009-04-02 01:37:03 -07003818static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 int acceptFD, option;
3820 struct sockaddr_un peeraddr;
3821 socklen_t socklen = sizeof (peeraddr);
3822 int data;
3823 unsigned int qxdm_data[6];
3824 const char *deactData[1] = {"1"};
3825 char *actData[1];
3826 RIL_Dial dialData;
3827 int hangupData[1] = {1};
3828 int number;
3829 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003830 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3831 int sim_id = 0;
3832
3833 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003834
3835 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3836
3837 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003838 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003839 return;
3840 }
3841
3842 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003843 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003844 return;
3845 }
3846 args = (char **) malloc(sizeof(char*) * number);
3847
3848 for (int i = 0; i < number; i++) {
3849 int len;
3850 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003851 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003852 freeDebugCallbackArgs(i, args);
3853 return;
3854 }
3855 // +1 for null-term
3856 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003857 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003858 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003859 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003860 freeDebugCallbackArgs(i, args);
3861 return;
3862 }
3863 char * buf = args[i];
3864 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003865 if ((i+1) == number) {
3866 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3867 sim_id = atoi(args[i]);
3868 switch (sim_id) {
3869 case 0:
3870 socket_id = RIL_SOCKET_1;
3871 break;
3872 #if (SIM_COUNT >= 2)
3873 case 1:
3874 socket_id = RIL_SOCKET_2;
3875 break;
3876 #endif
3877 #if (SIM_COUNT >= 3)
3878 case 2:
3879 socket_id = RIL_SOCKET_3;
3880 break;
3881 #endif
3882 #if (SIM_COUNT >= 4)
3883 case 3:
3884 socket_id = RIL_SOCKET_4;
3885 break;
3886 #endif
3887 default:
3888 socket_id = RIL_SOCKET_1;
3889 break;
3890 }
3891 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003892 }
3893
3894 switch (atoi(args[0])) {
3895 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003896 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003897 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003898 break;
3899 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003900 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003901 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003902 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003903 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003904 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3905 close(s_ril_param_socket.fdCommand);
3906 s_ril_param_socket.fdCommand = -1;
3907 }
3908 #if (SIM_COUNT == 2)
3909 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3910 close(s_ril_param_socket2.fdCommand);
3911 s_ril_param_socket2.fdCommand = -1;
3912 }
3913 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003914 break;
3915 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003916 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003917 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003918 break;
3919 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003920 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003921 qxdm_data[0] = 65536; // head.func_tag
3922 qxdm_data[1] = 16; // head.len
3923 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3924 qxdm_data[3] = 32; // log_file_size: 32megabytes
3925 qxdm_data[4] = 0; // log_mask
3926 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003927 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003928 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003929 break;
3930 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003931 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003932 qxdm_data[0] = 65536;
3933 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003934 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003935 qxdm_data[3] = 32;
3936 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003937 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003938 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003939 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003940 break;
3941 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003942 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003943 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003944 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003945 sleep(2);
3946 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003947 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003948 break;
3949 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003950 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003951 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003952 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003953 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003954 break;
3955 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003956 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003957 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003958 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003959 break;
3960 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003961 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003962 dialData.clir = 0;
3963 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003964 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003965 break;
3966 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003967 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003968 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003969 break;
3970 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003971 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003972 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003973 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003974 break;
3975 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003976 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003977 break;
3978 }
3979 freeDebugCallbackArgs(number, args);
3980 close(acceptFD);
3981}
3982
3983
Wink Savillef4c4d362009-04-02 01:37:03 -07003984static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003985 UserCallbackInfo *p_info;
3986
3987 p_info = (UserCallbackInfo *)param;
3988
3989 p_info->p_callback(p_info->userParam);
3990
3991
3992 // FIXME generalize this...there should be a cancel mechanism
3993 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3994 s_last_wake_timeout_info = NULL;
3995 }
3996
3997 free(p_info);
3998}
3999
4000
4001static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004002eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004003 int ret;
4004 int filedes[2];
4005
4006 ril_event_init();
4007
4008 pthread_mutex_lock(&s_startupMutex);
4009
4010 s_started = 1;
4011 pthread_cond_broadcast(&s_startupCond);
4012
4013 pthread_mutex_unlock(&s_startupMutex);
4014
4015 ret = pipe(filedes);
4016
4017 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004018 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004019 return NULL;
4020 }
4021
4022 s_fdWakeupRead = filedes[0];
4023 s_fdWakeupWrite = filedes[1];
4024
4025 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4026
4027 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4028 processWakeupCallback, NULL);
4029
4030 rilEventAddWakeup (&s_wakeupfd_event);
4031
4032 // Only returns on error
4033 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004034 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004035 // kill self to restart on error
4036 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004037
4038 return NULL;
4039}
4040
Wink Saville7f856802009-06-09 10:23:37 -07004041extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004042RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004043 /* spin up eventLoop thread and wait for it to get started */
4044 s_started = 0;
4045 pthread_mutex_lock(&s_startupMutex);
4046
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004047 pthread_attr_t attr;
4048 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004049 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004050
Elliott Hughesfd81e712014-01-06 12:46:02 -08004051 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4052 if (result != 0) {
4053 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004054 goto done;
4055 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004056
4057 while (s_started == 0) {
4058 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4059 }
4060
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004061done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004062 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004063}
4064
4065// Used for testing purpose only.
4066extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4067 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4068}
4069
Etan Cohend3652192014-06-20 08:28:44 -07004070static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4071 int fdListen = -1;
4072 int ret;
4073 char socket_name[10];
4074
4075 memset(socket_name, 0, sizeof(char)*10);
4076
4077 switch(socket_id) {
4078 case RIL_SOCKET_1:
4079 strncpy(socket_name, RIL_getRilSocketName(), 9);
4080 break;
4081 #if (SIM_COUNT >= 2)
4082 case RIL_SOCKET_2:
4083 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4084 break;
4085 #endif
4086 #if (SIM_COUNT >= 3)
4087 case RIL_SOCKET_3:
4088 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4089 break;
4090 #endif
4091 #if (SIM_COUNT >= 4)
4092 case RIL_SOCKET_4:
4093 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4094 break;
4095 #endif
4096 default:
4097 RLOGE("Socket id is wrong!!");
4098 return;
4099 }
4100
4101 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4102
4103 fdListen = android_get_control_socket(socket_name);
4104 if (fdListen < 0) {
4105 RLOGE("Failed to get socket %s", socket_name);
4106 exit(-1);
4107 }
4108
4109 ret = listen(fdListen, 4);
4110
4111 if (ret < 0) {
4112 RLOGE("Failed to listen on control socket '%d': %s",
4113 fdListen, strerror(errno));
4114 exit(-1);
4115 }
4116 socket_listen_p->fdListen = fdListen;
4117
4118 /* note: non-persistent so we can accept only one connection at a time */
4119 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4120 listenCallback, socket_listen_p);
4121
4122 rilEventAddWakeup (socket_listen_p->listen_event);
4123}
4124
Wink Saville7f856802009-06-09 10:23:37 -07004125extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004126RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004127 int ret;
4128 int flags;
4129
Etan Cohend3652192014-06-20 08:28:44 -07004130 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4131
Wink Saville43808972011-01-13 17:39:51 -08004132 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004133 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004134 return;
4135 }
Wink Saville43808972011-01-13 17:39:51 -08004136 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004137 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004138 callbacks->version, RIL_VERSION_MIN);
4139 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004140 }
Wink Saville43808972011-01-13 17:39:51 -08004141 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004142 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004143 callbacks->version, RIL_VERSION);
4144 return;
4145 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004146 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004147
4148 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004149 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004150 "Subsequent call ignored");
4151 return;
4152 }
4153
4154 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4155
Etan Cohend3652192014-06-20 08:28:44 -07004156 /* Initialize socket1 parameters */
4157 s_ril_param_socket = {
4158 RIL_SOCKET_1, /* socket_id */
4159 -1, /* fdListen */
4160 -1, /* fdCommand */
4161 PHONE_PROCESS, /* processName */
4162 &s_commands_event, /* commands_event */
4163 &s_listen_event, /* listen_event */
4164 processCommandsCallback, /* processCommandsCallback */
4165 NULL /* p_rs */
4166 };
4167
4168#if (SIM_COUNT >= 2)
4169 s_ril_param_socket2 = {
4170 RIL_SOCKET_2, /* socket_id */
4171 -1, /* fdListen */
4172 -1, /* fdCommand */
4173 PHONE_PROCESS, /* processName */
4174 &s_commands_event_socket2, /* commands_event */
4175 &s_listen_event_socket2, /* listen_event */
4176 processCommandsCallback, /* processCommandsCallback */
4177 NULL /* p_rs */
4178 };
4179#endif
4180
4181#if (SIM_COUNT >= 3)
4182 s_ril_param_socket3 = {
4183 RIL_SOCKET_3, /* socket_id */
4184 -1, /* fdListen */
4185 -1, /* fdCommand */
4186 PHONE_PROCESS, /* processName */
4187 &s_commands_event_socket3, /* commands_event */
4188 &s_listen_event_socket3, /* listen_event */
4189 processCommandsCallback, /* processCommandsCallback */
4190 NULL /* p_rs */
4191 };
4192#endif
4193
4194#if (SIM_COUNT >= 4)
4195 s_ril_param_socket4 = {
4196 RIL_SOCKET_4, /* socket_id */
4197 -1, /* fdListen */
4198 -1, /* fdCommand */
4199 PHONE_PROCESS, /* processName */
4200 &s_commands_event_socket4, /* commands_event */
4201 &s_listen_event_socket4, /* listen_event */
4202 processCommandsCallback, /* processCommandsCallback */
4203 NULL /* p_rs */
4204 };
4205#endif
4206
4207
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004208 s_registerCalled = 1;
4209
Etan Cohend3652192014-06-20 08:28:44 -07004210 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004211 // Little self-check
4212
Wink Savillef4c4d362009-04-02 01:37:03 -07004213 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004214 assert(i == s_commands[i].requestNumber);
4215 }
4216
Wink Savillef4c4d362009-04-02 01:37:03 -07004217 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004218 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004219 == s_unsolResponses[i].requestNumber);
4220 }
4221
4222 // New rild impl calls RIL_startEventLoop() first
4223 // old standalone impl wants it here.
4224
4225 if (s_started == 0) {
4226 RIL_startEventLoop();
4227 }
4228
Etan Cohend3652192014-06-20 08:28:44 -07004229 // start listen socket1
4230 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004231
Etan Cohend3652192014-06-20 08:28:44 -07004232#if (SIM_COUNT >= 2)
4233 // start listen socket2
4234 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4235#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004236
Etan Cohend3652192014-06-20 08:28:44 -07004237#if (SIM_COUNT >= 3)
4238 // start listen socket3
4239 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4240#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004241
Etan Cohend3652192014-06-20 08:28:44 -07004242#if (SIM_COUNT >= 4)
4243 // start listen socket4
4244 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4245#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004246
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004247
4248#if 1
4249 // start debug interface socket
4250
Etan Cohend3652192014-06-20 08:28:44 -07004251 char *inst = NULL;
4252 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4253 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4254 }
4255
4256 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4257 if (inst != NULL) {
4258 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4259 }
4260
4261 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004262 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004263 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004264 exit(-1);
4265 }
4266
4267 ret = listen(s_fdDebug, 4);
4268
4269 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004270 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004271 s_fdDebug, strerror(errno));
4272 exit(-1);
4273 }
4274
4275 ril_event_set (&s_debug_event, s_fdDebug, true,
4276 debugCallback, NULL);
4277
4278 rilEventAddWakeup (&s_debug_event);
4279#endif
4280
4281}
4282
4283static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004284checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004285 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004286 /* Hook for current context
4287 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4288 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4289 /* pendingRequestsHook refer to &s_pendingRequests */
4290 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004291
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004292 if (pRI == NULL) {
4293 return 0;
4294 }
4295
Etan Cohend3652192014-06-20 08:28:44 -07004296#if (SIM_COUNT >= 2)
4297 if (pRI->socket_id == RIL_SOCKET_2) {
4298 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4299 pendingRequestsHook = &s_pendingRequests_socket2;
4300 }
4301#if (SIM_COUNT >= 3)
4302 if (pRI->socket_id == RIL_SOCKET_3) {
4303 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4304 pendingRequestsHook = &s_pendingRequests_socket3;
4305 }
4306#endif
4307#if (SIM_COUNT >= 4)
4308 if (pRI->socket_id == RIL_SOCKET_4) {
4309 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4310 pendingRequestsHook = &s_pendingRequests_socket4;
4311 }
4312#endif
4313#endif
4314 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004315
Etan Cohend3652192014-06-20 08:28:44 -07004316 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004317 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004318 ; ppCur = &((*ppCur)->p_next)
4319 ) {
4320 if (pRI == *ppCur) {
4321 ret = 1;
4322
4323 *ppCur = (*ppCur)->p_next;
4324 break;
4325 }
4326 }
4327
Etan Cohend3652192014-06-20 08:28:44 -07004328 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004329
4330 return ret;
4331}
4332
4333
4334extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004335RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004336 RequestInfo *pRI;
4337 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004338 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004339 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004340 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004341
4342 pRI = (RequestInfo *)t;
4343
Jayachandran C6c607592014-08-04 15:48:01 -07004344 if (!checkAndDequeueRequestInfo(pRI)) {
4345 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4346 return;
4347 }
4348
Etan Cohend3652192014-06-20 08:28:44 -07004349 socket_id = pRI->socket_id;
4350#if (SIM_COUNT >= 2)
4351 if (socket_id == RIL_SOCKET_2) {
4352 fd = s_ril_param_socket2.fdCommand;
4353 }
4354#if (SIM_COUNT >= 3)
4355 if (socket_id == RIL_SOCKET_3) {
4356 fd = s_ril_param_socket3.fdCommand;
4357 }
4358#endif
4359#if (SIM_COUNT >= 4)
4360 if (socket_id == RIL_SOCKET_4) {
4361 fd = s_ril_param_socket4.fdCommand;
4362 }
4363#endif
4364#endif
4365 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4366
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004367 if (pRI->local > 0) {
4368 // Locally issued command...void only!
4369 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004370 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004371
4372 goto done;
4373 }
4374
4375 appendPrintBuf("[%04d]< %s",
4376 pRI->token, requestToString(pRI->pCI->requestNumber));
4377
4378 if (pRI->cancelled == 0) {
4379 Parcel p;
4380
4381 p.writeInt32 (RESPONSE_SOLICITED);
4382 p.writeInt32 (pRI->token);
4383 errorOffset = p.dataPosition();
4384
4385 p.writeInt32 (e);
4386
johnwangb2a61842009-06-02 14:55:45 -07004387 if (response != NULL) {
4388 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004389 ret = pRI->pCI->responseFunction(p, response, responselen);
4390
4391 /* if an error occurred, rewind and mark it */
4392 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004393 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004394 p.setDataPosition(errorOffset);
4395 p.writeInt32 (ret);
4396 }
johnwangb2a61842009-06-02 14:55:45 -07004397 }
4398
4399 if (e != RIL_E_SUCCESS) {
4400 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004401 }
4402
Etan Cohend3652192014-06-20 08:28:44 -07004403 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004404 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004405 }
Etan Cohend3652192014-06-20 08:28:44 -07004406 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004407 }
4408
4409done:
4410 free(pRI);
4411}
4412
4413
4414static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004415grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004416 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4417}
4418
4419static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004420releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004421 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4422}
4423
4424/**
4425 * Timer callback to put us back to sleep before the default timeout
4426 */
4427static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004428wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004429 // We're using "param != NULL" as a cancellation mechanism
4430 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004431 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004432
4433 releaseWakeLock();
4434 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004435 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004436 }
4437}
4438
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004439static int
4440decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4441 switch (radioState) {
4442 case RADIO_STATE_SIM_NOT_READY:
4443 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4444 case RADIO_STATE_SIM_READY:
4445 return RADIO_TECH_UMTS;
4446
4447 case RADIO_STATE_RUIM_NOT_READY:
4448 case RADIO_STATE_RUIM_READY:
4449 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4450 case RADIO_STATE_NV_NOT_READY:
4451 case RADIO_STATE_NV_READY:
4452 return RADIO_TECH_1xRTT;
4453
4454 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004455 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004456 return -1;
4457 }
4458}
4459
4460static int
4461decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4462 switch (radioState) {
4463 case RADIO_STATE_SIM_NOT_READY:
4464 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4465 case RADIO_STATE_SIM_READY:
4466 case RADIO_STATE_RUIM_NOT_READY:
4467 case RADIO_STATE_RUIM_READY:
4468 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4469 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4470
4471 case RADIO_STATE_NV_NOT_READY:
4472 case RADIO_STATE_NV_READY:
4473 return CDMA_SUBSCRIPTION_SOURCE_NV;
4474
4475 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004476 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004477 return -1;
4478 }
4479}
4480
4481static int
4482decodeSimStatus (RIL_RadioState radioState) {
4483 switch (radioState) {
4484 case RADIO_STATE_SIM_NOT_READY:
4485 case RADIO_STATE_RUIM_NOT_READY:
4486 case RADIO_STATE_NV_NOT_READY:
4487 case RADIO_STATE_NV_READY:
4488 return -1;
4489 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4490 case RADIO_STATE_SIM_READY:
4491 case RADIO_STATE_RUIM_READY:
4492 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4493 return radioState;
4494 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004495 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004496 return -1;
4497 }
4498}
4499
4500static bool is3gpp2(int radioTech) {
4501 switch (radioTech) {
4502 case RADIO_TECH_IS95A:
4503 case RADIO_TECH_IS95B:
4504 case RADIO_TECH_1xRTT:
4505 case RADIO_TECH_EVDO_0:
4506 case RADIO_TECH_EVDO_A:
4507 case RADIO_TECH_EVDO_B:
4508 case RADIO_TECH_EHRPD:
4509 return true;
4510 default:
4511 return false;
4512 }
4513}
4514
4515/* If RIL sends SIM states or RUIM states, store the voice radio
4516 * technology and subscription source information so that they can be
4517 * returned when telephony framework requests them
4518 */
4519static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004520processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004521
4522 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4523 int newVoiceRadioTech;
4524 int newCdmaSubscriptionSource;
4525 int newSimStatus;
4526
4527 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4528 from Radio State and send change notifications if there has been a change */
4529 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4530 if(newVoiceRadioTech != voiceRadioTech) {
4531 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004532 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4533 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004534 }
4535 if(is3gpp2(newVoiceRadioTech)) {
4536 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4537 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4538 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004539 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4540 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004541 }
4542 }
4543 newSimStatus = decodeSimStatus(newRadioState);
4544 if(newSimStatus != simRuimStatus) {
4545 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004546 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004547 }
4548
4549 /* Send RADIO_ON to telephony */
4550 newRadioState = RADIO_STATE_ON;
4551 }
4552
4553 return newRadioState;
4554}
4555
Etan Cohend3652192014-06-20 08:28:44 -07004556
4557#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004558extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004559void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4560 size_t datalen, RIL_SOCKET_ID socket_id)
4561#else
4562extern "C"
4563void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004564 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004565#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004566{
4567 int unsolResponseIndex;
4568 int ret;
4569 int64_t timeReceived = 0;
4570 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004571 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004572 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4573
4574#if defined(ANDROID_MULTI_SIM)
4575 soc_id = socket_id;
4576#endif
4577
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004578
4579 if (s_registerCalled == 0) {
4580 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004581 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004582 return;
4583 }
Wink Saville7f856802009-06-09 10:23:37 -07004584
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004585 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4586
4587 if ((unsolResponseIndex < 0)
4588 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004589 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004590 return;
4591 }
4592
4593 // Grab a wake lock if needed for this reponse,
4594 // as we exit we'll either release it immediately
4595 // or set a timer to release it later.
4596 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4597 case WAKE_PARTIAL:
4598 grabPartialWakeLock();
4599 shouldScheduleTimeout = true;
4600 break;
4601
4602 case DONT_WAKE:
4603 default:
4604 // No wake lock is grabed so don't set timeout
4605 shouldScheduleTimeout = false;
4606 break;
4607 }
4608
4609 // Mark the time this was received, doing this
4610 // after grabing the wakelock incase getting
4611 // the elapsedRealTime might cause us to goto
4612 // sleep.
4613 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4614 timeReceived = elapsedRealtime();
4615 }
4616
4617 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4618
4619 Parcel p;
4620
4621 p.writeInt32 (RESPONSE_UNSOLICITED);
4622 p.writeInt32 (unsolResponse);
4623
4624 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004625 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004626 if (ret != 0) {
4627 // Problem with the response. Don't continue;
4628 goto error_exit;
4629 }
4630
4631 // some things get more payload
4632 switch(unsolResponse) {
4633 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004634 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004635 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004636 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004637 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004638 break;
4639
4640
4641 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4642 // Store the time that this was received so the
4643 // handler of this message can account for
4644 // the time it takes to arrive and process. In
4645 // particular the system has been known to sleep
4646 // before this message can be processed.
4647 p.writeInt64(timeReceived);
4648 break;
4649 }
4650
Etan Cohend3652192014-06-20 08:28:44 -07004651 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4652 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004653 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4654
4655 // Unfortunately, NITZ time is not poll/update like everything
4656 // else in the system. So, if the upstream client isn't connected,
4657 // keep a copy of the last NITZ response (with receive time noted
4658 // above) around so we can deliver it when it is connected
4659
4660 if (s_lastNITZTimeData != NULL) {
4661 free (s_lastNITZTimeData);
4662 s_lastNITZTimeData = NULL;
4663 }
4664
4665 s_lastNITZTimeData = malloc(p.dataSize());
4666 s_lastNITZTimeDataSize = p.dataSize();
4667 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4668 }
4669
4670 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4671 // FIXME The java code should handshake here to release wake lock
4672
4673 if (shouldScheduleTimeout) {
4674 // Cancel the previous request
4675 if (s_last_wake_timeout_info != NULL) {
4676 s_last_wake_timeout_info->userParam = (void *)1;
4677 }
4678
4679 s_last_wake_timeout_info
4680 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4681 &TIMEVAL_WAKE_TIMEOUT);
4682 }
4683
4684 // Normal exit
4685 return;
4686
4687error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004688 if (shouldScheduleTimeout) {
4689 releaseWakeLock();
4690 }
4691}
4692
Wink Saville7f856802009-06-09 10:23:37 -07004693/** FIXME generalize this if you track UserCAllbackInfo, clear it
4694 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004695*/
4696static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004697internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004698 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004699{
4700 struct timeval myRelativeTime;
4701 UserCallbackInfo *p_info;
4702
4703 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4704
Wink Saville7f856802009-06-09 10:23:37 -07004705 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004706 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004707
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004708 if (relativeTime == NULL) {
4709 /* treat null parameter as a 0 relative time */
4710 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4711 } else {
4712 /* FIXME I think event_add's tv param is really const anyway */
4713 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4714 }
4715
4716 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4717
4718 ril_timer_add(&(p_info->event), &myRelativeTime);
4719
4720 triggerEvLoop();
4721 return p_info;
4722}
4723
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004724
4725extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004726RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4727 const struct timeval *relativeTime) {
4728 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004729}
4730
4731const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004732failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004733 switch(e) {
4734 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004735 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004736 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4737 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4738 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4739 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4740 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4741 case RIL_E_CANCELLED: return "E_CANCELLED";
4742 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4743 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4744 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004745 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004746 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004747#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004748 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4749 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4750#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004751 default: return "<unknown error>";
4752 }
4753}
4754
4755const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004756radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004757 switch(s) {
4758 case RADIO_STATE_OFF: return "RADIO_OFF";
4759 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4760 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4761 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4762 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004763 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4764 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4765 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4766 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4767 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004768 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004769 default: return "<unknown state>";
4770 }
4771}
4772
4773const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004774callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004775 switch(s) {
4776 case RIL_CALL_ACTIVE : return "ACTIVE";
4777 case RIL_CALL_HOLDING: return "HOLDING";
4778 case RIL_CALL_DIALING: return "DIALING";
4779 case RIL_CALL_ALERTING: return "ALERTING";
4780 case RIL_CALL_INCOMING: return "INCOMING";
4781 case RIL_CALL_WAITING: return "WAITING";
4782 default: return "<unknown state>";
4783 }
4784}
4785
4786const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004787requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004788/*
4789 cat libs/telephony/ril_commands.h \
4790 | egrep "^ *{RIL_" \
4791 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4792
4793
4794 cat libs/telephony/ril_unsol_commands.h \
4795 | egrep "^ *{RIL_" \
4796 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4797
4798*/
4799 switch(request) {
4800 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4801 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4802 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4803 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4804 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4805 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4806 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4807 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4808 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4809 case RIL_REQUEST_DIAL: return "DIAL";
4810 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4811 case RIL_REQUEST_HANGUP: return "HANGUP";
4812 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4813 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4814 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4815 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4816 case RIL_REQUEST_UDUB: return "UDUB";
4817 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4818 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004819 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4820 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004821 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4822 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4823 case RIL_REQUEST_DTMF: return "DTMF";
4824 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4825 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004826 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004827 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4828 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4829 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4830 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4831 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4832 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4833 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4834 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4835 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4836 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4837 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4838 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4839 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004840 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004841 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4842 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4843 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4844 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4845 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4846 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4847 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4848 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4849 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4850 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4851 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4852 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4853 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4854 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4855 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4856 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4857 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004858 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4859 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004860 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4861 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4862 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004863 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4864 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004865 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4866 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4867 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4868 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4869 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4870 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4871 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4872 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004873 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004874 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4875 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4876 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4877 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4878 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4879 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4880 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4881 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4882 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4883 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004884 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4885 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4886 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4887 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4888 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004889 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004890 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4891 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4892 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4893 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004894 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4895 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4896 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004897 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004898 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004899 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004900 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004901 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4902 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004903 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004904 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4905 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004906 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004907 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4908 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004909 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4910 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4911 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4912 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004913 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4914 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07004915 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4916 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004917 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4918 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004919 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4920 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004921 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004922 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4923 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004924 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 -08004925 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4926 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4927 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4928 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4929 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4930 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4931 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4932 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4933 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4934 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4935 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4936 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4937 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004938 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004939 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004940 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4941 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4942 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4943 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004944 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4945 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4946 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4947 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4948 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004949 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004950 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004951 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004952 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004953 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4954 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004955 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004956 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004957 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004958 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004959 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4960 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4961 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004962 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07004963 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004964 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004965 default: return "<unknown request>";
4966 }
4967}
4968
Etan Cohend3652192014-06-20 08:28:44 -07004969const char *
4970rilSocketIdToString(RIL_SOCKET_ID socket_id)
4971{
4972 switch(socket_id) {
4973 case RIL_SOCKET_1:
4974 return "RIL_SOCKET_1";
4975#if (SIM_COUNT >= 2)
4976 case RIL_SOCKET_2:
4977 return "RIL_SOCKET_2";
4978#endif
4979#if (SIM_COUNT >= 3)
4980 case RIL_SOCKET_3:
4981 return "RIL_SOCKET_3";
4982#endif
4983#if (SIM_COUNT >= 4)
4984 case RIL_SOCKET_4:
4985 return "RIL_SOCKET_4";
4986#endif
4987 default:
4988 return "not a valid RIL";
4989 }
4990}
4991
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004992} /* namespace android */