blob: 5c4b93aa32d818888bd0c948b2628284107aff84 [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);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800308static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
309static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
310static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
311
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800312#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700313#if defined(ANDROID_MULTI_SIM)
314extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
315 size_t datalen, RIL_SOCKET_ID socket_id);
316#else
Wink Saville7f856802009-06-09 10:23:37 -0700317extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800318 size_t datalen);
319#endif
Etan Cohend3652192014-06-20 08:28:44 -0700320#endif
321
322#if defined(ANDROID_MULTI_SIM)
323#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
324#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
325#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
326#else
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
330#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331
Wink Saville7f856802009-06-09 10:23:37 -0700332static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700333 (RIL_TimedCallback callback, void *param,
334 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
336/** Index == requestNumber */
337static CommandInfo s_commands[] = {
338#include "ril_commands.h"
339};
340
341static UnsolResponseInfo s_unsolResponses[] = {
342#include "ril_unsol_commands.h"
343};
344
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800345/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
346 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
347 radio state message and store it. Every time there is a change in Radio State
348 check to see if voice radio tech changes and notify telephony
349 */
350int voiceRadioTech = -1;
351
352/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
353 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
354 source from radio state and store it. Every time there is a change in Radio State
355 check to see if subscription source changed and notify telephony
356 */
357int cdmaSubscriptionSource = -1;
358
359/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
360 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
361 check to see if SIM/RUIM status changed and notify telephony
362 */
363int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800364
Etan Cohend3652192014-06-20 08:28:44 -0700365static char * RIL_getRilSocketName() {
366 return rild;
367}
368
369extern "C"
370void RIL_setRilSocketName(char * s) {
371 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
372}
373
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800374static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700375strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800376 size_t stringlen;
377 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700378
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700380
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800381 return strndup16to8(s16, stringlen);
382}
383
Wink Saville8b4e4f72014-10-17 15:01:45 -0700384static status_t
385readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
386 size_t s16Len;
387 const char16_t *s16;
388
389 s16 = p.readString16Inplace(&s16Len);
390 if (s16 == NULL) {
391 return NO_MEMORY;
392 }
393 size_t strLen = strnlen16to8(s16, s16Len);
394 if ((strLen + 1) > maxLen) {
395 return NO_MEMORY;
396 }
397 if (strncpy16to8(str, s16, strLen) == NULL) {
398 return NO_MEMORY;
399 } else {
400 return NO_ERROR;
401 }
402}
403
Wink Savillef4c4d362009-04-02 01:37:03 -0700404static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800405 char16_t *s16;
406 size_t s16_len;
407 s16 = strdup8to16(s, &s16_len);
408 p.writeString16(s16, s16_len);
409 free(s16);
410}
411
412
413static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700414memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800415 if (s != NULL) {
416 memset (s, 0, strlen(s));
417 }
418}
419
420void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
421 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700422 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800423 // do nothing -- the data reference lives longer than the Parcel object
424}
425
Wink Saville7f856802009-06-09 10:23:37 -0700426/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 * To be called from dispatch thread
428 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700429 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430 */
431static void
Etan Cohend3652192014-06-20 08:28:44 -0700432issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433 RequestInfo *pRI;
434 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700435 /* Hook for current context */
436 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
437 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
438 /* pendingRequestsHook refer to &s_pendingRequests */
439 RequestInfo** pendingRequestsHook = &s_pendingRequests;
440
441#if (SIM_COUNT == 2)
442 if (socket_id == RIL_SOCKET_2) {
443 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
444 pendingRequestsHook = &s_pendingRequests_socket2;
445 }
446#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800447
448 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
449
450 pRI->local = 1;
451 pRI->token = 0xffffffff; // token is not used in this context
452 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700453 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800454
Etan Cohend3652192014-06-20 08:28:44 -0700455 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800456 assert (ret == 0);
457
Etan Cohend3652192014-06-20 08:28:44 -0700458 pRI->p_next = *pendingRequestsHook;
459 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460
Etan Cohend3652192014-06-20 08:28:44 -0700461 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462 assert (ret == 0);
463
Wink Saville8eb2a122012-11-19 16:05:13 -0800464 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465
Etan Cohend3652192014-06-20 08:28:44 -0700466 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800467}
468
469
470
471static int
Etan Cohend3652192014-06-20 08:28:44 -0700472processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800473 Parcel p;
474 status_t status;
475 int32_t request;
476 int32_t token;
477 RequestInfo *pRI;
478 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700479 /* Hook for current context */
480 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
481 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
482 /* pendingRequestsHook refer to &s_pendingRequests */
483 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800484
485 p.setData((uint8_t *) buffer, buflen);
486
487 // status checked at end
488 status = p.readInt32(&request);
489 status = p.readInt32 (&token);
490
Etan Cohend3652192014-06-20 08:28:44 -0700491 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
492
493#if (SIM_COUNT >= 2)
494 if (socket_id == RIL_SOCKET_2) {
495 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
496 pendingRequestsHook = &s_pendingRequests_socket2;
497 }
498#if (SIM_COUNT >= 3)
499 else if (socket_id == RIL_SOCKET_3) {
500 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
501 pendingRequestsHook = &s_pendingRequests_socket3;
502 }
503#endif
504#if (SIM_COUNT >= 4)
505 else if (socket_id == RIL_SOCKET_4) {
506 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
507 pendingRequestsHook = &s_pendingRequests_socket4;
508 }
509#endif
510#endif
511
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800512 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800513 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514 return 0;
515 }
516
517 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700518 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800519 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700521 pErr.writeInt32 (RESPONSE_SOLICITED);
522 pErr.writeInt32 (token);
523 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
524
525 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800526 return 0;
527 }
528
529
530 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
531
532 pRI->token = token;
533 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700534 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800535
Etan Cohend3652192014-06-20 08:28:44 -0700536 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537 assert (ret == 0);
538
Etan Cohend3652192014-06-20 08:28:44 -0700539 pRI->p_next = *pendingRequestsHook;
540 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541
Etan Cohend3652192014-06-20 08:28:44 -0700542 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543 assert (ret == 0);
544
545/* sLastDispatchedToken = token; */
546
Wink Saville7f856802009-06-09 10:23:37 -0700547 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800548
549 return 0;
550}
551
552static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700553invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800554 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800555 pRI->token, requestToString(pRI->pCI->requestNumber));
556}
557
558/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700559static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700560dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800561 clearPrintBuf;
562 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700563 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800564}
565
566/** Callee expects const char * */
567static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700568dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800569 status_t status;
570 size_t datalen;
571 size_t stringlen;
572 char *string8 = NULL;
573
574 string8 = strdupReadString(p);
575
576 startRequest;
577 appendPrintBuf("%s%s", printBuf, string8);
578 closeRequest;
579 printRequest(pRI->token, pRI->pCI->requestNumber);
580
Etan Cohend3652192014-06-20 08:28:44 -0700581 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
582 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800583
584#ifdef MEMSET_FREED
585 memsetString(string8);
586#endif
587
588 free(string8);
589 return;
590invalid:
591 invalidCommandBlock(pRI);
592 return;
593}
594
595/** Callee expects const char ** */
596static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700597dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800598 int32_t countStrings;
599 status_t status;
600 size_t datalen;
601 char **pStrings;
602
603 status = p.readInt32 (&countStrings);
604
605 if (status != NO_ERROR) {
606 goto invalid;
607 }
608
609 startRequest;
610 if (countStrings == 0) {
611 // just some non-null pointer
612 pStrings = (char **)alloca(sizeof(char *));
613 datalen = 0;
614 } else if (((int)countStrings) == -1) {
615 pStrings = NULL;
616 datalen = 0;
617 } else {
618 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700619
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800620 pStrings = (char **)alloca(datalen);
621
622 for (int i = 0 ; i < countStrings ; i++) {
623 pStrings[i] = strdupReadString(p);
624 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
625 }
626 }
627 removeLastChar;
628 closeRequest;
629 printRequest(pRI->token, pRI->pCI->requestNumber);
630
Etan Cohend3652192014-06-20 08:28:44 -0700631 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800632
633 if (pStrings != NULL) {
634 for (int i = 0 ; i < countStrings ; i++) {
635#ifdef MEMSET_FREED
636 memsetString (pStrings[i]);
637#endif
638 free(pStrings[i]);
639 }
640
641#ifdef MEMSET_FREED
642 memset(pStrings, 0, datalen);
643#endif
644 }
Wink Saville7f856802009-06-09 10:23:37 -0700645
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800646 return;
647invalid:
648 invalidCommandBlock(pRI);
649 return;
650}
651
652/** Callee expects const int * */
653static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700654dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800655 int32_t count;
656 status_t status;
657 size_t datalen;
658 int *pInts;
659
660 status = p.readInt32 (&count);
661
662 if (status != NO_ERROR || count == 0) {
663 goto invalid;
664 }
665
666 datalen = sizeof(int) * count;
667 pInts = (int *)alloca(datalen);
668
669 startRequest;
670 for (int i = 0 ; i < count ; i++) {
671 int32_t t;
672
673 status = p.readInt32(&t);
674 pInts[i] = (int)t;
675 appendPrintBuf("%s%d,", printBuf, t);
676
677 if (status != NO_ERROR) {
678 goto invalid;
679 }
680 }
681 removeLastChar;
682 closeRequest;
683 printRequest(pRI->token, pRI->pCI->requestNumber);
684
Etan Cohend3652192014-06-20 08:28:44 -0700685 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
686 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800687
688#ifdef MEMSET_FREED
689 memset(pInts, 0, datalen);
690#endif
691
692 return;
693invalid:
694 invalidCommandBlock(pRI);
695 return;
696}
697
698
Wink Saville7f856802009-06-09 10:23:37 -0700699/**
700 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800701 * Payload is:
702 * int32_t status
703 * String pdu
704 */
705static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700706dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800707 RIL_SMS_WriteArgs args;
708 int32_t t;
709 status_t status;
710
711 memset (&args, 0, sizeof(args));
712
713 status = p.readInt32(&t);
714 args.status = (int)t;
715
716 args.pdu = strdupReadString(p);
717
718 if (status != NO_ERROR || args.pdu == NULL) {
719 goto invalid;
720 }
721
722 args.smsc = strdupReadString(p);
723
724 startRequest;
725 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
726 (char*)args.pdu, (char*)args.smsc);
727 closeRequest;
728 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700729
Etan Cohend3652192014-06-20 08:28:44 -0700730 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800731
732#ifdef MEMSET_FREED
733 memsetString (args.pdu);
734#endif
735
736 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700737
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800738#ifdef MEMSET_FREED
739 memset(&args, 0, sizeof(args));
740#endif
741
742 return;
743invalid:
744 invalidCommandBlock(pRI);
745 return;
746}
747
Wink Saville7f856802009-06-09 10:23:37 -0700748/**
749 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800750 * Payload is:
751 * String address
752 * int32_t clir
753 */
754static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700755dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800756 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800757 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800758 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800759 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800760 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800761 status_t status;
762
763 memset (&dial, 0, sizeof(dial));
764
765 dial.address = strdupReadString(p);
766
767 status = p.readInt32(&t);
768 dial.clir = (int)t;
769
770 if (status != NO_ERROR || dial.address == NULL) {
771 goto invalid;
772 }
773
Wink Saville3a4840b2010-04-07 13:29:58 -0700774 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800775 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800776 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800777 } else {
778 status = p.readInt32(&uusPresent);
779
780 if (status != NO_ERROR) {
781 goto invalid;
782 }
783
784 if (uusPresent == 0) {
785 dial.uusInfo = NULL;
786 } else {
787 int32_t len;
788
789 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
790
791 status = p.readInt32(&t);
792 uusInfo.uusType = (RIL_UUS_Type) t;
793
794 status = p.readInt32(&t);
795 uusInfo.uusDcs = (RIL_UUS_DCS) t;
796
797 status = p.readInt32(&len);
798 if (status != NO_ERROR) {
799 goto invalid;
800 }
801
802 // The java code writes -1 for null arrays
803 if (((int) len) == -1) {
804 uusInfo.uusData = NULL;
805 len = 0;
806 } else {
807 uusInfo.uusData = (char*) p.readInplace(len);
808 }
809
810 uusInfo.uusLength = len;
811 dial.uusInfo = &uusInfo;
812 }
Wink Saville7bce0822010-01-08 15:20:12 -0800813 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800814 }
815
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800816 startRequest;
817 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800818 if (uusPresent) {
819 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
820 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
821 dial.uusInfo->uusLength);
822 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800823 closeRequest;
824 printRequest(pRI->token, pRI->pCI->requestNumber);
825
Etan Cohend3652192014-06-20 08:28:44 -0700826 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800827
828#ifdef MEMSET_FREED
829 memsetString (dial.address);
830#endif
831
832 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700833
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800834#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800835 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800836 memset(&dial, 0, sizeof(dial));
837#endif
838
839 return;
840invalid:
841 invalidCommandBlock(pRI);
842 return;
843}
844
Wink Saville7f856802009-06-09 10:23:37 -0700845/**
846 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800847 * Payload is:
848 * int32_t command
849 * int32_t fileid
850 * String path
851 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700852 * String data
853 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800854 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855 */
856static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700857dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800858 union RIL_SIM_IO {
859 RIL_SIM_IO_v6 v6;
860 RIL_SIM_IO_v5 v5;
861 } simIO;
862
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800864 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800865 status_t status;
866
867 memset (&simIO, 0, sizeof(simIO));
868
Wink Saville7f856802009-06-09 10:23:37 -0700869 // note we only check status at the end
870
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800872 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873
874 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800875 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876
Wink Savillec0114b32011-02-18 10:14:07 -0800877 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878
879 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800880 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800881
882 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800883 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884
885 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800886 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887
Wink Savillec0114b32011-02-18 10:14:07 -0800888 simIO.v6.data = strdupReadString(p);
889 simIO.v6.pin2 = strdupReadString(p);
890 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891
892 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800893 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
894 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
895 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
896 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897 closeRequest;
898 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700899
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800900 if (status != NO_ERROR) {
901 goto invalid;
902 }
903
Wink Savillec0114b32011-02-18 10:14:07 -0800904 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700905 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800906
907#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800908 memsetString (simIO.v6.path);
909 memsetString (simIO.v6.data);
910 memsetString (simIO.v6.pin2);
911 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800912#endif
913
Wink Savillec0114b32011-02-18 10:14:07 -0800914 free (simIO.v6.path);
915 free (simIO.v6.data);
916 free (simIO.v6.pin2);
917 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700918
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800919#ifdef MEMSET_FREED
920 memset(&simIO, 0, sizeof(simIO));
921#endif
922
923 return;
924invalid:
925 invalidCommandBlock(pRI);
926 return;
927}
928
929/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800930 * Callee expects const RIL_SIM_APDU *
931 * Payload is:
932 * int32_t sessionid
933 * int32_t cla
934 * int32_t instruction
935 * int32_t p1, p2, p3
936 * String data
937 */
938static void
939dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
940 int32_t t;
941 status_t status;
942 RIL_SIM_APDU apdu;
943
944 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
945
946 // Note we only check status at the end. Any single failure leads to
947 // subsequent reads filing.
948 status = p.readInt32(&t);
949 apdu.sessionid = (int)t;
950
951 status = p.readInt32(&t);
952 apdu.cla = (int)t;
953
954 status = p.readInt32(&t);
955 apdu.instruction = (int)t;
956
957 status = p.readInt32(&t);
958 apdu.p1 = (int)t;
959
960 status = p.readInt32(&t);
961 apdu.p2 = (int)t;
962
963 status = p.readInt32(&t);
964 apdu.p3 = (int)t;
965
966 apdu.data = strdupReadString(p);
967
968 startRequest;
969 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
970 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
971 apdu.p3, (char*)apdu.data);
972 closeRequest;
973 printRequest(pRI->token, pRI->pCI->requestNumber);
974
975 if (status != NO_ERROR) {
976 goto invalid;
977 }
978
Etan Cohend3652192014-06-20 08:28:44 -0700979 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800980
981#ifdef MEMSET_FREED
982 memsetString(apdu.data);
983#endif
984 free(apdu.data);
985
986#ifdef MEMSET_FREED
987 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
988#endif
989
990 return;
991invalid:
992 invalidCommandBlock(pRI);
993 return;
994}
995
996
997/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800998 * Callee expects const RIL_CallForwardInfo *
999 * Payload is:
1000 * int32_t status/action
1001 * int32_t reason
1002 * int32_t serviceCode
1003 * int32_t toa
1004 * String number (0 length -> null)
1005 * int32_t timeSeconds
1006 */
Wink Saville7f856802009-06-09 10:23:37 -07001007static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001008dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001009 RIL_CallForwardInfo cff;
1010 int32_t t;
1011 status_t status;
1012
1013 memset (&cff, 0, sizeof(cff));
1014
Wink Saville7f856802009-06-09 10:23:37 -07001015 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001016
1017 status = p.readInt32(&t);
1018 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001019
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001020 status = p.readInt32(&t);
1021 cff.reason = (int)t;
1022
1023 status = p.readInt32(&t);
1024 cff.serviceClass = (int)t;
1025
1026 status = p.readInt32(&t);
1027 cff.toa = (int)t;
1028
1029 cff.number = strdupReadString(p);
1030
1031 status = p.readInt32(&t);
1032 cff.timeSeconds = (int)t;
1033
1034 if (status != NO_ERROR) {
1035 goto invalid;
1036 }
1037
1038 // special case: number 0-length fields is null
1039
1040 if (cff.number != NULL && strlen (cff.number) == 0) {
1041 cff.number = NULL;
1042 }
1043
1044 startRequest;
1045 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1046 cff.status, cff.reason, cff.serviceClass, cff.toa,
1047 (char*)cff.number, cff.timeSeconds);
1048 closeRequest;
1049 printRequest(pRI->token, pRI->pCI->requestNumber);
1050
Etan Cohend3652192014-06-20 08:28:44 -07001051 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001052
1053#ifdef MEMSET_FREED
1054 memsetString(cff.number);
1055#endif
1056
1057 free (cff.number);
1058
1059#ifdef MEMSET_FREED
1060 memset(&cff, 0, sizeof(cff));
1061#endif
1062
1063 return;
1064invalid:
1065 invalidCommandBlock(pRI);
1066 return;
1067}
1068
1069
Wink Saville7f856802009-06-09 10:23:37 -07001070static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001071dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001072 int32_t len;
1073 status_t status;
1074 const void *data;
1075
1076 status = p.readInt32(&len);
1077
1078 if (status != NO_ERROR) {
1079 goto invalid;
1080 }
1081
1082 // The java code writes -1 for null arrays
1083 if (((int)len) == -1) {
1084 data = NULL;
1085 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001086 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001087
1088 data = p.readInplace(len);
1089
1090 startRequest;
1091 appendPrintBuf("%sraw_size=%d", printBuf, len);
1092 closeRequest;
1093 printRequest(pRI->token, pRI->pCI->requestNumber);
1094
Etan Cohend3652192014-06-20 08:28:44 -07001095 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001096
1097 return;
1098invalid:
1099 invalidCommandBlock(pRI);
1100 return;
1101}
1102
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001103static status_t
1104constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001105 int32_t t;
1106 uint8_t ut;
1107 status_t status;
1108 int32_t digitCount;
1109 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001110
Wink Savillef4c4d362009-04-02 01:37:03 -07001111 memset(&rcsm, 0, sizeof(rcsm));
1112
1113 status = p.readInt32(&t);
1114 rcsm.uTeleserviceID = (int) t;
1115
1116 status = p.read(&ut,sizeof(ut));
1117 rcsm.bIsServicePresent = (uint8_t) ut;
1118
1119 status = p.readInt32(&t);
1120 rcsm.uServicecategory = (int) t;
1121
1122 status = p.readInt32(&t);
1123 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1124
1125 status = p.readInt32(&t);
1126 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1127
1128 status = p.readInt32(&t);
1129 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1130
1131 status = p.readInt32(&t);
1132 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1133
1134 status = p.read(&ut,sizeof(ut));
1135 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1136
1137 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1138 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1139 status = p.read(&ut,sizeof(ut));
1140 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1141 }
1142
Wink Saville7f856802009-06-09 10:23:37 -07001143 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001144 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1145
Wink Saville7f856802009-06-09 10:23:37 -07001146 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001147 rcsm.sSubAddress.odd = (uint8_t) ut;
1148
1149 status = p.read(&ut,sizeof(ut));
1150 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1151
1152 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001153 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1154 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001155 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1156 }
1157
Wink Saville7f856802009-06-09 10:23:37 -07001158 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 rcsm.uBearerDataLen = (int) t;
1160
1161 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001162 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1163 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001164 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1165 }
1166
1167 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001168 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001169 }
1170
1171 startRequest;
1172 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001173 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001174 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001175 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001176 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001177
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 printRequest(pRI->token, pRI->pCI->requestNumber);
1179
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001180 return status;
1181}
1182
1183static void
1184dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1185 RIL_CDMA_SMS_Message rcsm;
1186
1187 ALOGD("dispatchCdmaSms");
1188 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1189 goto invalid;
1190 }
1191
Etan Cohend3652192014-06-20 08:28:44 -07001192 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001193
1194#ifdef MEMSET_FREED
1195 memset(&rcsm, 0, sizeof(rcsm));
1196#endif
1197
1198 return;
1199
1200invalid:
1201 invalidCommandBlock(pRI);
1202 return;
1203}
1204
Wink Saville7f856802009-06-09 10:23:37 -07001205static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001206dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1207 RIL_IMS_SMS_Message rism;
1208 RIL_CDMA_SMS_Message rcsm;
1209
1210 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1211
1212 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1213 goto invalid;
1214 }
1215 memset(&rism, 0, sizeof(rism));
1216 rism.tech = RADIO_TECH_3GPP2;
1217 rism.retry = retry;
1218 rism.messageRef = messageRef;
1219 rism.message.cdmaMessage = &rcsm;
1220
Etan Cohend3652192014-06-20 08:28:44 -07001221 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001222 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001223 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001224
1225#ifdef MEMSET_FREED
1226 memset(&rcsm, 0, sizeof(rcsm));
1227 memset(&rism, 0, sizeof(rism));
1228#endif
1229
1230 return;
1231
1232invalid:
1233 invalidCommandBlock(pRI);
1234 return;
1235}
1236
1237static void
1238dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1239 RIL_IMS_SMS_Message rism;
1240 int32_t countStrings;
1241 status_t status;
1242 size_t datalen;
1243 char **pStrings;
1244 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1245
1246 status = p.readInt32 (&countStrings);
1247
1248 if (status != NO_ERROR) {
1249 goto invalid;
1250 }
1251
1252 memset(&rism, 0, sizeof(rism));
1253 rism.tech = RADIO_TECH_3GPP;
1254 rism.retry = retry;
1255 rism.messageRef = messageRef;
1256
1257 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001258 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1259 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001260 if (countStrings == 0) {
1261 // just some non-null pointer
1262 pStrings = (char **)alloca(sizeof(char *));
1263 datalen = 0;
1264 } else if (((int)countStrings) == -1) {
1265 pStrings = NULL;
1266 datalen = 0;
1267 } else {
1268 datalen = sizeof(char *) * countStrings;
1269
1270 pStrings = (char **)alloca(datalen);
1271
1272 for (int i = 0 ; i < countStrings ; i++) {
1273 pStrings[i] = strdupReadString(p);
1274 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1275 }
1276 }
1277 removeLastChar;
1278 closeRequest;
1279 printRequest(pRI->token, pRI->pCI->requestNumber);
1280
1281 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001282 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001283 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001284 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001285
1286 if (pStrings != NULL) {
1287 for (int i = 0 ; i < countStrings ; i++) {
1288#ifdef MEMSET_FREED
1289 memsetString (pStrings[i]);
1290#endif
1291 free(pStrings[i]);
1292 }
1293
1294#ifdef MEMSET_FREED
1295 memset(pStrings, 0, datalen);
1296#endif
1297 }
1298
1299#ifdef MEMSET_FREED
1300 memset(&rism, 0, sizeof(rism));
1301#endif
1302 return;
1303invalid:
1304 ALOGE("dispatchImsGsmSms invalid block");
1305 invalidCommandBlock(pRI);
1306 return;
1307}
1308
1309static void
1310dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1311 int32_t t;
1312 status_t status = p.readInt32(&t);
1313 RIL_RadioTechnologyFamily format;
1314 uint8_t retry;
1315 int32_t messageRef;
1316
1317 ALOGD("dispatchImsSms");
1318 if (status != NO_ERROR) {
1319 goto invalid;
1320 }
1321 format = (RIL_RadioTechnologyFamily) t;
1322
1323 // read retry field
1324 status = p.read(&retry,sizeof(retry));
1325 if (status != NO_ERROR) {
1326 goto invalid;
1327 }
1328 // read messageRef field
1329 status = p.read(&messageRef,sizeof(messageRef));
1330 if (status != NO_ERROR) {
1331 goto invalid;
1332 }
1333
1334 if (RADIO_TECH_3GPP == format) {
1335 dispatchImsGsmSms(p, pRI, retry, messageRef);
1336 } else if (RADIO_TECH_3GPP2 == format) {
1337 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1338 } else {
1339 ALOGE("requestImsSendSMS invalid format value =%d", format);
1340 }
1341
1342 return;
1343
1344invalid:
1345 invalidCommandBlock(pRI);
1346 return;
1347}
1348
1349static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001350dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1351 RIL_CDMA_SMS_Ack rcsa;
1352 int32_t t;
1353 status_t status;
1354 int32_t digitCount;
1355
1356 memset(&rcsa, 0, sizeof(rcsa));
1357
1358 status = p.readInt32(&t);
1359 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1360
1361 status = p.readInt32(&t);
1362 rcsa.uSMSCauseCode = (int) t;
1363
1364 if (status != NO_ERROR) {
1365 goto invalid;
1366 }
1367
1368 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001369 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1370 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001371 closeRequest;
1372
1373 printRequest(pRI->token, pRI->pCI->requestNumber);
1374
Etan Cohend3652192014-06-20 08:28:44 -07001375 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001376
1377#ifdef MEMSET_FREED
1378 memset(&rcsa, 0, sizeof(rcsa));
1379#endif
1380
1381 return;
1382
1383invalid:
1384 invalidCommandBlock(pRI);
1385 return;
1386}
1387
Wink Savillea592eeb2009-05-22 13:26:36 -07001388static void
1389dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1390 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001391 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001392 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001393
Wink Savillea592eeb2009-05-22 13:26:36 -07001394 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001395 if (status != NO_ERROR) {
1396 goto invalid;
1397 }
1398
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001399 {
1400 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1401 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001402
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001403 startRequest;
1404 for (int i = 0 ; i < num ; i++ ) {
1405 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001406
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001407 status = p.readInt32(&t);
1408 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001409
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001410 status = p.readInt32(&t);
1411 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001412
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001413 status = p.readInt32(&t);
1414 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001415
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001416 status = p.readInt32(&t);
1417 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001418
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 status = p.readInt32(&t);
1420 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001422 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1423 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1424 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1425 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1426 gsmBci[i].selected);
1427 }
1428 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001429
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001430 if (status != NO_ERROR) {
1431 goto invalid;
1432 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001433
Etan Cohend3652192014-06-20 08:28:44 -07001434 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001435 gsmBciPtrs,
1436 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001437 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001438
1439#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001440 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1441 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001442#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001443 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001444
1445 return;
1446
1447invalid:
1448 invalidCommandBlock(pRI);
1449 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001450}
Wink Savillef4c4d362009-04-02 01:37:03 -07001451
Wink Savillea592eeb2009-05-22 13:26:36 -07001452static void
1453dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1454 int32_t t;
1455 status_t status;
1456 int32_t num;
1457
1458 status = p.readInt32(&num);
1459 if (status != NO_ERROR) {
1460 goto invalid;
1461 }
1462
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001463 {
1464 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1465 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001466
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 startRequest;
1468 for (int i = 0 ; i < num ; i++ ) {
1469 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001470
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001471 status = p.readInt32(&t);
1472 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001473
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 status = p.readInt32(&t);
1475 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001476
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001477 status = p.readInt32(&t);
1478 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001480 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1481 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1482 cdmaBci[i].language, cdmaBci[i].selected);
1483 }
1484 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001486 if (status != NO_ERROR) {
1487 goto invalid;
1488 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001489
Etan Cohend3652192014-06-20 08:28:44 -07001490 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001491 cdmaBciPtrs,
1492 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001493 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001494
1495#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001496 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1497 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001498#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001499 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001500
1501 return;
1502
1503invalid:
1504 invalidCommandBlock(pRI);
1505 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001506}
1507
1508static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1509 RIL_CDMA_SMS_WriteArgs rcsw;
1510 int32_t t;
1511 uint32_t ut;
1512 uint8_t uct;
1513 status_t status;
1514 int32_t digitCount;
1515
1516 memset(&rcsw, 0, sizeof(rcsw));
1517
1518 status = p.readInt32(&t);
1519 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001520
Wink Savillef4c4d362009-04-02 01:37:03 -07001521 status = p.readInt32(&t);
1522 rcsw.message.uTeleserviceID = (int) t;
1523
1524 status = p.read(&uct,sizeof(uct));
1525 rcsw.message.bIsServicePresent = (uint8_t) uct;
1526
1527 status = p.readInt32(&t);
1528 rcsw.message.uServicecategory = (int) t;
1529
1530 status = p.readInt32(&t);
1531 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1532
1533 status = p.readInt32(&t);
1534 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1535
1536 status = p.readInt32(&t);
1537 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1538
1539 status = p.readInt32(&t);
1540 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1541
1542 status = p.read(&uct,sizeof(uct));
1543 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1544
1545 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1546 status = p.read(&uct,sizeof(uct));
1547 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1548 }
1549
Wink Savillea592eeb2009-05-22 13:26:36 -07001550 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001551 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1552
Wink Savillea592eeb2009-05-22 13:26:36 -07001553 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001554 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1555
1556 status = p.read(&uct,sizeof(uct));
1557 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1558
1559 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001560 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001561 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1562 }
1563
Wink Savillea592eeb2009-05-22 13:26:36 -07001564 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001565 rcsw.message.uBearerDataLen = (int) t;
1566
1567 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001568 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001569 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1570 }
1571
1572 if (status != NO_ERROR) {
1573 goto invalid;
1574 }
1575
1576 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001577 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1578 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1579 message.sAddress.number_mode=%d, \
1580 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001581 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001582 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1583 rcsw.message.sAddress.number_mode,
1584 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 closeRequest;
1586
1587 printRequest(pRI->token, pRI->pCI->requestNumber);
1588
Etan Cohend3652192014-06-20 08:28:44 -07001589 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001590
1591#ifdef MEMSET_FREED
1592 memset(&rcsw, 0, sizeof(rcsw));
1593#endif
1594
1595 return;
1596
1597invalid:
1598 invalidCommandBlock(pRI);
1599 return;
1600
1601}
1602
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001603// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1604// Version 4 of the RIL interface adds a new PDP type parameter to support
1605// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1606// RIL, remove the parameter from the request.
1607static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1608 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1609 const int numParamsRilV3 = 6;
1610
1611 // The first bytes of the RIL parcel contain the request number and the
1612 // serial number - see processCommandBuffer(). Copy them over too.
1613 int pos = p.dataPosition();
1614
1615 int numParams = p.readInt32();
1616 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1617 Parcel p2;
1618 p2.appendFrom(&p, 0, pos);
1619 p2.writeInt32(numParamsRilV3);
1620 for(int i = 0; i < numParamsRilV3; i++) {
1621 p2.writeString16(p.readString16());
1622 }
1623 p2.setDataPosition(pos);
1624 dispatchStrings(p2, pRI);
1625 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001626 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001627 dispatchStrings(p, pRI);
1628 }
1629}
1630
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001631// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1632// When all RILs handle this request, this function can be removed and
1633// the request can be sent directly to the RIL using dispatchVoid.
1634static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001635 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001636
1637 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1638 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1639 }
1640
1641 // RILs that support RADIO_STATE_ON should support this request.
1642 if (RADIO_STATE_ON == state) {
1643 dispatchVoid(p, pRI);
1644 return;
1645 }
1646
1647 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1648 // will not support this new request either and decode Voice Radio Technology
1649 // from Radio State
1650 voiceRadioTech = decodeVoiceRadioTechnology(state);
1651
1652 if (voiceRadioTech < 0)
1653 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1654 else
1655 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1656}
1657
1658// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1659// When all RILs handle this request, this function can be removed and
1660// the request can be sent directly to the RIL using dispatchVoid.
1661static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001662 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001663
1664 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1665 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1666 }
1667
1668 // RILs that support RADIO_STATE_ON should support this request.
1669 if (RADIO_STATE_ON == state) {
1670 dispatchVoid(p, pRI);
1671 return;
1672 }
1673
1674 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1675 // will not support this new request either and decode CDMA Subscription Source
1676 // from Radio State
1677 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1678
1679 if (cdmaSubscriptionSource < 0)
1680 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1681 else
1682 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1683}
1684
Sungmin Choi75697532013-04-26 15:04:45 -07001685static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1686{
1687 RIL_InitialAttachApn pf;
1688 int32_t t;
1689 status_t status;
1690
1691 memset(&pf, 0, sizeof(pf));
1692
1693 pf.apn = strdupReadString(p);
1694 pf.protocol = strdupReadString(p);
1695
1696 status = p.readInt32(&t);
1697 pf.authtype = (int) t;
1698
1699 pf.username = strdupReadString(p);
1700 pf.password = strdupReadString(p);
1701
1702 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001703 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1704 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001705 closeRequest;
1706 printRequest(pRI->token, pRI->pCI->requestNumber);
1707
1708 if (status != NO_ERROR) {
1709 goto invalid;
1710 }
Etan Cohend3652192014-06-20 08:28:44 -07001711 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001712
1713#ifdef MEMSET_FREED
1714 memsetString(pf.apn);
1715 memsetString(pf.protocol);
1716 memsetString(pf.username);
1717 memsetString(pf.password);
1718#endif
1719
1720 free(pf.apn);
1721 free(pf.protocol);
1722 free(pf.username);
1723 free(pf.password);
1724
1725#ifdef MEMSET_FREED
1726 memset(&pf, 0, sizeof(pf));
1727#endif
1728
1729 return;
1730invalid:
1731 invalidCommandBlock(pRI);
1732 return;
1733}
1734
Jake Hamby8a4a2332014-01-15 13:12:05 -08001735static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1736 RIL_NV_ReadItem nvri;
1737 int32_t t;
1738 status_t status;
1739
1740 memset(&nvri, 0, sizeof(nvri));
1741
1742 status = p.readInt32(&t);
1743 nvri.itemID = (RIL_NV_Item) t;
1744
1745 if (status != NO_ERROR) {
1746 goto invalid;
1747 }
1748
1749 startRequest;
1750 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1751 closeRequest;
1752
1753 printRequest(pRI->token, pRI->pCI->requestNumber);
1754
Etan Cohend3652192014-06-20 08:28:44 -07001755 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001756
1757#ifdef MEMSET_FREED
1758 memset(&nvri, 0, sizeof(nvri));
1759#endif
1760
1761 return;
1762
1763invalid:
1764 invalidCommandBlock(pRI);
1765 return;
1766}
1767
1768static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1769 RIL_NV_WriteItem nvwi;
1770 int32_t t;
1771 status_t status;
1772
1773 memset(&nvwi, 0, sizeof(nvwi));
1774
1775 status = p.readInt32(&t);
1776 nvwi.itemID = (RIL_NV_Item) t;
1777
1778 nvwi.value = strdupReadString(p);
1779
1780 if (status != NO_ERROR || nvwi.value == NULL) {
1781 goto invalid;
1782 }
1783
1784 startRequest;
1785 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1786 nvwi.value);
1787 closeRequest;
1788
1789 printRequest(pRI->token, pRI->pCI->requestNumber);
1790
Etan Cohend3652192014-06-20 08:28:44 -07001791 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001792
1793#ifdef MEMSET_FREED
1794 memsetString(nvwi.value);
1795#endif
1796
1797 free(nvwi.value);
1798
1799#ifdef MEMSET_FREED
1800 memset(&nvwi, 0, sizeof(nvwi));
1801#endif
1802
1803 return;
1804
1805invalid:
1806 invalidCommandBlock(pRI);
1807 return;
1808}
1809
1810
Etan Cohend3652192014-06-20 08:28:44 -07001811static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1812 RIL_SelectUiccSub uicc_sub;
1813 status_t status;
1814 int32_t t;
1815 memset(&uicc_sub, 0, sizeof(uicc_sub));
1816
1817 status = p.readInt32(&t);
1818 if (status != NO_ERROR) {
1819 goto invalid;
1820 }
1821 uicc_sub.slot = (int) t;
1822
1823 status = p.readInt32(&t);
1824 if (status != NO_ERROR) {
1825 goto invalid;
1826 }
1827 uicc_sub.app_index = (int) t;
1828
1829 status = p.readInt32(&t);
1830 if (status != NO_ERROR) {
1831 goto invalid;
1832 }
1833 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1834
1835 status = p.readInt32(&t);
1836 if (status != NO_ERROR) {
1837 goto invalid;
1838 }
1839 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1840
1841 startRequest;
1842 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1843 uicc_sub.act_status);
1844 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1845 uicc_sub.app_index, uicc_sub.act_status);
1846 closeRequest;
1847 printRequest(pRI->token, pRI->pCI->requestNumber);
1848
1849 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1850
1851#ifdef MEMSET_FREED
1852 memset(&uicc_sub, 0, sizeof(uicc_sub));
1853#endif
1854 return;
1855
1856invalid:
1857 invalidCommandBlock(pRI);
1858 return;
1859}
1860
Amit Mahajan90530a62014-07-01 15:54:08 -07001861static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1862{
1863 RIL_SimAuthentication pf;
1864 int32_t t;
1865 status_t status;
1866
1867 memset(&pf, 0, sizeof(pf));
1868
1869 status = p.readInt32(&t);
1870 pf.authContext = (int) t;
1871 pf.authData = strdupReadString(p);
1872 pf.aid = strdupReadString(p);
1873
1874 startRequest;
1875 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1876 closeRequest;
1877 printRequest(pRI->token, pRI->pCI->requestNumber);
1878
1879 if (status != NO_ERROR) {
1880 goto invalid;
1881 }
1882 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1883
1884#ifdef MEMSET_FREED
1885 memsetString(pf.authData);
1886 memsetString(pf.aid);
1887#endif
1888
1889 free(pf.authData);
1890 free(pf.aid);
1891
1892#ifdef MEMSET_FREED
1893 memset(&pf, 0, sizeof(pf));
1894#endif
1895
1896 return;
1897invalid:
1898 invalidCommandBlock(pRI);
1899 return;
1900}
1901
Amit Mahajanc796e222014-08-13 16:54:01 +00001902static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1903 int32_t t;
1904 status_t status;
1905 int32_t num;
1906
1907 status = p.readInt32(&num);
1908 if (status != NO_ERROR) {
1909 goto invalid;
1910 }
1911
1912 {
1913 RIL_DataProfileInfo dataProfiles[num];
1914 RIL_DataProfileInfo *dataProfilePtrs[num];
1915
1916 startRequest;
1917 for (int i = 0 ; i < num ; i++ ) {
1918 dataProfilePtrs[i] = &dataProfiles[i];
1919
1920 status = p.readInt32(&t);
1921 dataProfiles[i].profileId = (int) t;
1922
1923 dataProfiles[i].apn = strdupReadString(p);
1924 dataProfiles[i].protocol = strdupReadString(p);
1925 status = p.readInt32(&t);
1926 dataProfiles[i].authType = (int) t;
1927
1928 dataProfiles[i].user = strdupReadString(p);
1929 dataProfiles[i].password = strdupReadString(p);
1930
1931 status = p.readInt32(&t);
1932 dataProfiles[i].type = (int) t;
1933
1934 status = p.readInt32(&t);
1935 dataProfiles[i].maxConnsTime = (int) t;
1936 status = p.readInt32(&t);
1937 dataProfiles[i].maxConns = (int) t;
1938 status = p.readInt32(&t);
1939 dataProfiles[i].waitTime = (int) t;
1940
1941 status = p.readInt32(&t);
1942 dataProfiles[i].enabled = (int) t;
1943
1944 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1945 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1946 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1947 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1948 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1949 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1950 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1951 }
1952 closeRequest;
1953 printRequest(pRI->token, pRI->pCI->requestNumber);
1954
1955 if (status != NO_ERROR) {
1956 goto invalid;
1957 }
1958 CALL_ONREQUEST(pRI->pCI->requestNumber,
1959 dataProfilePtrs,
1960 num * sizeof(RIL_DataProfileInfo *),
1961 pRI, pRI->socket_id);
1962
1963#ifdef MEMSET_FREED
1964 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1965 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1966#endif
1967 }
1968
1969 return;
1970
1971invalid:
1972 invalidCommandBlock(pRI);
1973 return;
1974}
1975
Wink Saville8b4e4f72014-10-17 15:01:45 -07001976static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1977 RIL_RadioCapability rc;
1978 int32_t t;
1979 status_t status;
1980
1981 memset (&rc, 0, sizeof(RIL_RadioCapability));
1982
1983 status = p.readInt32(&t);
1984 rc.version = (int)t;
1985 if (status != NO_ERROR) {
1986 goto invalid;
1987 }
1988
1989 status = p.readInt32(&t);
1990 rc.session= (int)t;
1991 if (status != NO_ERROR) {
1992 goto invalid;
1993 }
1994
1995 status = p.readInt32(&t);
1996 rc.phase= (int)t;
1997 if (status != NO_ERROR) {
1998 goto invalid;
1999 }
2000
2001 status = p.readInt32(&t);
2002 rc.rat = (int)t;
2003 if (status != NO_ERROR) {
2004 goto invalid;
2005 }
2006
2007 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2008 if (status != NO_ERROR) {
2009 goto invalid;
2010 }
2011
2012 status = p.readInt32(&t);
2013 rc.status = (int)t;
2014
2015 if (status != NO_ERROR) {
2016 goto invalid;
2017 }
2018
2019 startRequest;
2020 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002021 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2022 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002023
2024 closeRequest;
2025 printRequest(pRI->token, pRI->pCI->requestNumber);
2026
2027 CALL_ONREQUEST(pRI->pCI->requestNumber,
2028 &rc,
2029 sizeof(RIL_RadioCapability),
2030 pRI, pRI->socket_id);
2031 return;
2032invalid:
2033 invalidCommandBlock(pRI);
2034 return;
2035}
2036
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002037static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002038blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002039 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002040 const uint8_t *toWrite;
2041
2042 toWrite = (const uint8_t *)buffer;
2043
2044 while (writeOffset < len) {
2045 ssize_t written;
2046 do {
2047 written = write (fd, toWrite + writeOffset,
2048 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302049 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002050
2051 if (written >= 0) {
2052 writeOffset += written;
2053 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002054 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002055 close(fd);
2056 return -1;
2057 }
2058 }
2059
2060 return 0;
2061}
2062
2063static int
Etan Cohend3652192014-06-20 08:28:44 -07002064sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2065 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002066 int ret;
2067 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002068 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002069
Etan Cohend3652192014-06-20 08:28:44 -07002070 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2071
2072#if (SIM_COUNT >= 2)
2073 if (socket_id == RIL_SOCKET_2) {
2074 fd = s_ril_param_socket2.fdCommand;
2075 writeMutexHook = &s_writeMutex_socket2;
2076 }
2077#if (SIM_COUNT >= 3)
2078 else if (socket_id == RIL_SOCKET_3) {
2079 fd = s_ril_param_socket3.fdCommand;
2080 writeMutexHook = &s_writeMutex_socket3;
2081 }
2082#endif
2083#if (SIM_COUNT >= 4)
2084 else if (socket_id == RIL_SOCKET_4) {
2085 fd = s_ril_param_socket4.fdCommand;
2086 writeMutexHook = &s_writeMutex_socket4;
2087 }
2088#endif
2089#endif
2090 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002091 return -1;
2092 }
2093
2094 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002095 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002096 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2097
2098 return -1;
2099 }
Wink Saville7f856802009-06-09 10:23:37 -07002100
Etan Cohend3652192014-06-20 08:28:44 -07002101 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002102
2103 header = htonl(dataSize);
2104
2105 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2106
2107 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002108 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002109 return ret;
2110 }
2111
Kennyee1fadc2009-08-13 00:45:53 +08002112 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002113
2114 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002115 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002116 return ret;
2117 }
2118
Etan Cohend3652192014-06-20 08:28:44 -07002119 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002120
2121 return 0;
2122}
2123
2124static int
Etan Cohend3652192014-06-20 08:28:44 -07002125sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002127 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002128}
2129
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002130/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002131
2132static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002133responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002134 int numInts;
2135
2136 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002137 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002138 return RIL_ERRNO_INVALID_RESPONSE;
2139 }
2140 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002141 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002142 (int)responselen, (int)sizeof(int));
2143 return RIL_ERRNO_INVALID_RESPONSE;
2144 }
2145
2146 int *p_int = (int *) response;
2147
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002148 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002149 p.writeInt32 (numInts);
2150
2151 /* each int*/
2152 startResponse;
2153 for (int i = 0 ; i < numInts ; i++) {
2154 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2155 p.writeInt32(p_int[i]);
2156 }
2157 removeLastChar;
2158 closeResponse;
2159
2160 return 0;
2161}
2162
Wink Saville43808972011-01-13 17:39:51 -08002163/** response is a char **, pointing to an array of char *'s
2164 The parcel will begin with the version */
2165static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2166 p.writeInt32(version);
2167 return responseStrings(p, response, responselen);
2168}
2169
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002170/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002171static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002172 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002173
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002174 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002175 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002176 return RIL_ERRNO_INVALID_RESPONSE;
2177 }
2178 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002179 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002180 (int)responselen, (int)sizeof(char *));
2181 return RIL_ERRNO_INVALID_RESPONSE;
2182 }
2183
2184 if (response == NULL) {
2185 p.writeInt32 (0);
2186 } else {
2187 char **p_cur = (char **) response;
2188
2189 numStrings = responselen / sizeof(char *);
2190 p.writeInt32 (numStrings);
2191
2192 /* each string*/
2193 startResponse;
2194 for (int i = 0 ; i < numStrings ; i++) {
2195 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2196 writeStringToParcel (p, p_cur[i]);
2197 }
2198 removeLastChar;
2199 closeResponse;
2200 }
2201 return 0;
2202}
2203
2204
2205/**
Wink Saville7f856802009-06-09 10:23:37 -07002206 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002207 * FIXME currently ignores responselen
2208 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002209static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002210 /* one string only */
2211 startResponse;
2212 appendPrintBuf("%s%s", printBuf, (char*)response);
2213 closeResponse;
2214
2215 writeStringToParcel(p, (const char *)response);
2216
2217 return 0;
2218}
2219
Wink Savillef4c4d362009-04-02 01:37:03 -07002220static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002221 startResponse;
2222 removeLastChar;
2223 return 0;
2224}
2225
Wink Savillef4c4d362009-04-02 01:37:03 -07002226static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002227 int num;
2228
2229 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002230 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002231 return RIL_ERRNO_INVALID_RESPONSE;
2232 }
2233
2234 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002235 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002236 (int)responselen, (int)sizeof (RIL_Call *));
2237 return RIL_ERRNO_INVALID_RESPONSE;
2238 }
2239
2240 startResponse;
2241 /* number of call info's */
2242 num = responselen / sizeof(RIL_Call *);
2243 p.writeInt32(num);
2244
2245 for (int i = 0 ; i < num ; i++) {
2246 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2247 /* each call info */
2248 p.writeInt32(p_cur->state);
2249 p.writeInt32(p_cur->index);
2250 p.writeInt32(p_cur->toa);
2251 p.writeInt32(p_cur->isMpty);
2252 p.writeInt32(p_cur->isMT);
2253 p.writeInt32(p_cur->als);
2254 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002255 p.writeInt32(p_cur->isVoicePrivacy);
2256 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002257 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002258 writeStringToParcel(p, p_cur->name);
2259 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002260 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002261 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2262 p.writeInt32(0); /* UUS Information is absent */
2263 } else {
2264 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2265 p.writeInt32(1); /* UUS Information is present */
2266 p.writeInt32(uusInfo->uusType);
2267 p.writeInt32(uusInfo->uusDcs);
2268 p.writeInt32(uusInfo->uusLength);
2269 p.write(uusInfo->uusData, uusInfo->uusLength);
2270 }
Wink Saville3d54e742009-05-18 18:00:44 -07002271 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002272 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002273 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002274 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002275 p_cur->toa);
2276 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2277 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002278 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002279 (p_cur->isMT)?"mt":"mo",
2280 p_cur->als,
2281 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002282 (p_cur->isVoicePrivacy)?"evp":"noevp");
2283 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2284 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002285 p_cur->number,
2286 p_cur->numberPresentation,
2287 p_cur->name,
2288 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002289 }
2290 removeLastChar;
2291 closeResponse;
2292
2293 return 0;
2294}
2295
Wink Savillef4c4d362009-04-02 01:37:03 -07002296static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002297 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002298 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002299 return RIL_ERRNO_INVALID_RESPONSE;
2300 }
2301
2302 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002303 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002304 (int)responselen, (int)sizeof (RIL_SMS_Response));
2305 return RIL_ERRNO_INVALID_RESPONSE;
2306 }
2307
2308 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2309
2310 p.writeInt32(p_cur->messageRef);
2311 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002312 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313
2314 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002315 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2316 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002317 closeResponse;
2318
2319 return 0;
2320}
2321
Wink Savillec0114b32011-02-18 10:14:07 -08002322static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002323{
2324 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002325 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002326 return RIL_ERRNO_INVALID_RESPONSE;
2327 }
2328
Wink Savillec0114b32011-02-18 10:14:07 -08002329 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002330 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002331 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002332 return RIL_ERRNO_INVALID_RESPONSE;
2333 }
2334
Amit Mahajan52500162014-07-29 17:36:48 -07002335 // Write version
2336 p.writeInt32(4);
2337
Wink Savillec0114b32011-02-18 10:14:07 -08002338 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002339 p.writeInt32(num);
2340
Wink Savillec0114b32011-02-18 10:14:07 -08002341 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002342 startResponse;
2343 int i;
2344 for (i = 0; i < num; i++) {
2345 p.writeInt32(p_cur[i].cid);
2346 p.writeInt32(p_cur[i].active);
2347 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002348 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002349 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002350 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002351 p_cur[i].cid,
2352 (p_cur[i].active==0)?"down":"up",
2353 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002354 (char*)p_cur[i].address);
2355 }
2356 removeLastChar;
2357 closeResponse;
2358
2359 return 0;
2360}
2361
Etan Cohend3652192014-06-20 08:28:44 -07002362static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2363{
Amit Mahajan52500162014-07-29 17:36:48 -07002364 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002365 RLOGE("invalid response: NULL");
2366 return RIL_ERRNO_INVALID_RESPONSE;
2367 }
2368
2369 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002370 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002371 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2372 return RIL_ERRNO_INVALID_RESPONSE;
2373 }
2374
Amit Mahajan52500162014-07-29 17:36:48 -07002375 // Write version
2376 p.writeInt32(6);
2377
Etan Cohend3652192014-06-20 08:28:44 -07002378 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2379 p.writeInt32(num);
2380
2381 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2382 startResponse;
2383 int i;
2384 for (i = 0; i < num; i++) {
2385 p.writeInt32((int)p_cur[i].status);
2386 p.writeInt32(p_cur[i].suggestedRetryTime);
2387 p.writeInt32(p_cur[i].cid);
2388 p.writeInt32(p_cur[i].active);
2389 writeStringToParcel(p, p_cur[i].type);
2390 writeStringToParcel(p, p_cur[i].ifname);
2391 writeStringToParcel(p, p_cur[i].addresses);
2392 writeStringToParcel(p, p_cur[i].dnses);
2393 writeStringToParcel(p, p_cur[i].gateways);
2394 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2395 p_cur[i].status,
2396 p_cur[i].suggestedRetryTime,
2397 p_cur[i].cid,
2398 (p_cur[i].active==0)?"down":"up",
2399 (char*)p_cur[i].type,
2400 (char*)p_cur[i].ifname,
2401 (char*)p_cur[i].addresses,
2402 (char*)p_cur[i].dnses,
2403 (char*)p_cur[i].gateways);
2404 }
2405 removeLastChar;
2406 closeResponse;
2407
2408 return 0;
2409}
2410
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002411static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2412{
2413 if (response == NULL && responselen != 0) {
2414 RLOGE("invalid response: NULL");
2415 return RIL_ERRNO_INVALID_RESPONSE;
2416 }
2417
2418 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2419 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2420 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2421 return RIL_ERRNO_INVALID_RESPONSE;
2422 }
2423
2424 // Write version
2425 p.writeInt32(10);
2426
2427 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2428 p.writeInt32(num);
2429
2430 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2431 startResponse;
2432 int i;
2433 for (i = 0; i < num; i++) {
2434 p.writeInt32((int)p_cur[i].status);
2435 p.writeInt32(p_cur[i].suggestedRetryTime);
2436 p.writeInt32(p_cur[i].cid);
2437 p.writeInt32(p_cur[i].active);
2438 writeStringToParcel(p, p_cur[i].type);
2439 writeStringToParcel(p, p_cur[i].ifname);
2440 writeStringToParcel(p, p_cur[i].addresses);
2441 writeStringToParcel(p, p_cur[i].dnses);
2442 writeStringToParcel(p, p_cur[i].gateways);
2443 writeStringToParcel(p, p_cur[i].pcscf);
2444 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2445 p_cur[i].status,
2446 p_cur[i].suggestedRetryTime,
2447 p_cur[i].cid,
2448 (p_cur[i].active==0)?"down":"up",
2449 (char*)p_cur[i].type,
2450 (char*)p_cur[i].ifname,
2451 (char*)p_cur[i].addresses,
2452 (char*)p_cur[i].dnses,
2453 (char*)p_cur[i].gateways,
2454 (char*)p_cur[i].pcscf);
2455 }
2456 removeLastChar;
2457 closeResponse;
2458
2459 return 0;
2460}
2461
2462
Wink Saville43808972011-01-13 17:39:51 -08002463static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2464{
Wink Saville43808972011-01-13 17:39:51 -08002465 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002466 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002467 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002468 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2469 return responseDataCallListV6(p, response, responselen);
2470 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2471 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002472 } else {
2473 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002474 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002475 return RIL_ERRNO_INVALID_RESPONSE;
2476 }
2477
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002478 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2479 RLOGE("invalid response length %d expected multiple of %d",
2480 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002481 return RIL_ERRNO_INVALID_RESPONSE;
2482 }
2483
Amit Mahajan52500162014-07-29 17:36:48 -07002484 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002485 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002486
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002487 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002488 p.writeInt32(num);
2489
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002490 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002491 startResponse;
2492 int i;
2493 for (i = 0; i < num; i++) {
2494 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002495 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002496 p.writeInt32(p_cur[i].cid);
2497 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002498 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002499 writeStringToParcel(p, p_cur[i].ifname);
2500 writeStringToParcel(p, p_cur[i].addresses);
2501 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002502 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002503 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002504 p.writeInt32(p_cur[i].mtu);
2505 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 -08002506 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002507 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002508 p_cur[i].cid,
2509 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002510 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002511 (char*)p_cur[i].ifname,
2512 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002513 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002514 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002515 (char*)p_cur[i].pcscf,
2516 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002517 }
2518 removeLastChar;
2519 closeResponse;
2520 }
2521
2522 return 0;
2523}
2524
2525static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2526{
2527 if (s_callbacks.version < 5) {
2528 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2529 } else {
2530 return responseDataCallList(p, response, responselen);
2531 }
2532}
2533
Wink Savillef4c4d362009-04-02 01:37:03 -07002534static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002535 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002536 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002537 return RIL_ERRNO_INVALID_RESPONSE;
2538 }
2539
2540 // The java code reads -1 size as null byte array
2541 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002542 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002543 } else {
2544 p.writeInt32(responselen);
2545 p.write(response, responselen);
2546 }
2547
2548 return 0;
2549}
2550
2551
Wink Savillef4c4d362009-04-02 01:37:03 -07002552static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002553 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002554 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002555 return RIL_ERRNO_INVALID_RESPONSE;
2556 }
2557
2558 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002559 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002560 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2561 return RIL_ERRNO_INVALID_RESPONSE;
2562 }
2563
2564 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2565 p.writeInt32(p_cur->sw1);
2566 p.writeInt32(p_cur->sw2);
2567 writeStringToParcel(p, p_cur->simResponse);
2568
2569 startResponse;
2570 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2571 (char*)p_cur->simResponse);
2572 closeResponse;
2573
2574
2575 return 0;
2576}
2577
Wink Savillef4c4d362009-04-02 01:37:03 -07002578static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002579 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002580
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002581 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002582 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002583 return RIL_ERRNO_INVALID_RESPONSE;
2584 }
2585
2586 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002587 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002588 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2589 return RIL_ERRNO_INVALID_RESPONSE;
2590 }
2591
2592 /* number of call info's */
2593 num = responselen / sizeof(RIL_CallForwardInfo *);
2594 p.writeInt32(num);
2595
2596 startResponse;
2597 for (int i = 0 ; i < num ; i++) {
2598 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2599
2600 p.writeInt32(p_cur->status);
2601 p.writeInt32(p_cur->reason);
2602 p.writeInt32(p_cur->serviceClass);
2603 p.writeInt32(p_cur->toa);
2604 writeStringToParcel(p, p_cur->number);
2605 p.writeInt32(p_cur->timeSeconds);
2606 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2607 (p_cur->status==1)?"enable":"disable",
2608 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2609 (char*)p_cur->number,
2610 p_cur->timeSeconds);
2611 }
2612 removeLastChar;
2613 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002614
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002615 return 0;
2616}
2617
Wink Savillef4c4d362009-04-02 01:37:03 -07002618static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002619 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002620 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002621 return RIL_ERRNO_INVALID_RESPONSE;
2622 }
2623
2624 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002625 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002626 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2627 return RIL_ERRNO_INVALID_RESPONSE;
2628 }
2629
2630 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2631 p.writeInt32(p_cur->notificationType);
2632 p.writeInt32(p_cur->code);
2633 p.writeInt32(p_cur->index);
2634 p.writeInt32(p_cur->type);
2635 writeStringToParcel(p, p_cur->number);
2636
2637 startResponse;
2638 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2639 (p_cur->notificationType==0)?"mo":"mt",
2640 p_cur->code, p_cur->index, p_cur->type,
2641 (char*)p_cur->number);
2642 closeResponse;
2643
2644 return 0;
2645}
2646
Wink Saville3d54e742009-05-18 18:00:44 -07002647static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002648 int num;
2649
2650 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002651 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002652 return RIL_ERRNO_INVALID_RESPONSE;
2653 }
2654
2655 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002656 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002657 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2658 return RIL_ERRNO_INVALID_RESPONSE;
2659 }
2660
2661 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002662 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002663 num = responselen / sizeof(RIL_NeighboringCell *);
2664 p.writeInt32(num);
2665
2666 for (int i = 0 ; i < num ; i++) {
2667 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2668
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002669 p.writeInt32(p_cur->rssi);
2670 writeStringToParcel (p, p_cur->cid);
2671
2672 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2673 p_cur->cid, p_cur->rssi);
2674 }
2675 removeLastChar;
2676 closeResponse;
2677
2678 return 0;
2679}
2680
Wink Saville3d54e742009-05-18 18:00:44 -07002681/**
2682 * Marshall the signalInfoRecord into the parcel if it exists.
2683 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002684static void marshallSignalInfoRecord(Parcel &p,
2685 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002686 p.writeInt32(p_signalInfoRecord.isPresent);
2687 p.writeInt32(p_signalInfoRecord.signalType);
2688 p.writeInt32(p_signalInfoRecord.alertPitch);
2689 p.writeInt32(p_signalInfoRecord.signal);
2690}
2691
Wink Savillea592eeb2009-05-22 13:26:36 -07002692static int responseCdmaInformationRecords(Parcel &p,
2693 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002694 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002695 char* string8 = NULL;
2696 int buffer_lenght;
2697 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002698
2699 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002700 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002701 return RIL_ERRNO_INVALID_RESPONSE;
2702 }
2703
Wink Savillea592eeb2009-05-22 13:26:36 -07002704 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002705 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002706 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002707 return RIL_ERRNO_INVALID_RESPONSE;
2708 }
2709
Wink Savillea592eeb2009-05-22 13:26:36 -07002710 RIL_CDMA_InformationRecords *p_cur =
2711 (RIL_CDMA_InformationRecords *) response;
2712 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002713
2714 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002715 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002716
Wink Savillea592eeb2009-05-22 13:26:36 -07002717 for (int i = 0 ; i < num ; i++) {
2718 infoRec = &p_cur->infoRec[i];
2719 p.writeInt32(infoRec->name);
2720 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002721 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002722 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2723 if (infoRec->rec.display.alpha_len >
2724 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002725 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002726 expected not more than %d\n",
2727 (int)infoRec->rec.display.alpha_len,
2728 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2729 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002730 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002731 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2732 * sizeof(char) );
2733 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2734 string8[i] = infoRec->rec.display.alpha_buf[i];
2735 }
Wink Saville43808972011-01-13 17:39:51 -08002736 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002737 writeStringToParcel(p, (const char*)string8);
2738 free(string8);
2739 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002740 break;
2741 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002742 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002743 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002744 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002745 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002746 expected not more than %d\n",
2747 (int)infoRec->rec.number.len,
2748 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2749 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002750 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002751 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2752 * sizeof(char) );
2753 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2754 string8[i] = infoRec->rec.number.buf[i];
2755 }
Wink Saville43808972011-01-13 17:39:51 -08002756 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002757 writeStringToParcel(p, (const char*)string8);
2758 free(string8);
2759 string8 = NULL;
2760 p.writeInt32(infoRec->rec.number.number_type);
2761 p.writeInt32(infoRec->rec.number.number_plan);
2762 p.writeInt32(infoRec->rec.number.pi);
2763 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002764 break;
2765 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002766 p.writeInt32(infoRec->rec.signal.isPresent);
2767 p.writeInt32(infoRec->rec.signal.signalType);
2768 p.writeInt32(infoRec->rec.signal.alertPitch);
2769 p.writeInt32(infoRec->rec.signal.signal);
2770
2771 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2772 alertPitch=%X, signal=%X, ",
2773 printBuf, (int)infoRec->rec.signal.isPresent,
2774 (int)infoRec->rec.signal.signalType,
2775 (int)infoRec->rec.signal.alertPitch,
2776 (int)infoRec->rec.signal.signal);
2777 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002778 break;
2779 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002780 if (infoRec->rec.redir.redirectingNumber.len >
2781 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002782 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002783 expected not more than %d\n",
2784 (int)infoRec->rec.redir.redirectingNumber.len,
2785 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2786 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002787 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002788 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2789 .len + 1) * sizeof(char) );
2790 for (int i = 0;
2791 i < infoRec->rec.redir.redirectingNumber.len;
2792 i++) {
2793 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2794 }
Wink Saville43808972011-01-13 17:39:51 -08002795 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002796 writeStringToParcel(p, (const char*)string8);
2797 free(string8);
2798 string8 = NULL;
2799 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2800 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2801 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2802 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2803 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002804 break;
2805 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002806 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2807 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2808 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2809 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2810
2811 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2812 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2813 lineCtrlPowerDenial=%d, ", printBuf,
2814 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2815 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2816 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2817 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2818 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002819 break;
2820 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002821 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002822
Wink Savillea592eeb2009-05-22 13:26:36 -07002823 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2824 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002825 break;
2826 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002827 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2828 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2829
2830 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2831 infoRec->rec.audioCtrl.upLink,
2832 infoRec->rec.audioCtrl.downLink);
2833 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002834 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002835 case RIL_CDMA_T53_RELEASE_INFO_REC:
2836 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002837 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002838 return RIL_ERRNO_INVALID_RESPONSE;
2839 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002840 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002841 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002842 }
2843 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002844 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002845
Wink Savillea592eeb2009-05-22 13:26:36 -07002846 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002847}
2848
Wink Savillea592eeb2009-05-22 13:26:36 -07002849static int responseRilSignalStrength(Parcel &p,
2850 void *response, size_t responselen) {
2851 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002852 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002853 return RIL_ERRNO_INVALID_RESPONSE;
2854 }
2855
Wink Savillec0114b32011-02-18 10:14:07 -08002856 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002857 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002858
Wink Saville3d54e742009-05-18 18:00:44 -07002859 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2860 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2861 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2862 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2863 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2864 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2865 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002866 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002867 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002868 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002869 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002870 if (s_callbacks.version <= 6) {
2871 // signalStrength: -1 -> 99
2872 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2873 p_cur->LTE_SignalStrength.signalStrength = 99;
2874 }
2875 // rsrp: -1 -> INT_MAX all other negative value to positive.
2876 // So remap here
2877 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2878 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2879 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2880 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2881 }
2882 // rsrq: -1 -> INT_MAX
2883 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2884 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2885 }
2886 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002887
Wink Saville18e4ab12013-04-07 17:31:04 -07002888 // cqi: -1 -> INT_MAX
2889 if (p_cur->LTE_SignalStrength.cqi == -1) {
2890 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2891 }
2892 }
2893 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002894 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2895 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2896 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2897 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002898 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2899 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2900 } else {
2901 p.writeInt32(INT_MAX);
2902 }
Wink Savillec0114b32011-02-18 10:14:07 -08002903 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002904 p.writeInt32(99);
2905 p.writeInt32(INT_MAX);
2906 p.writeInt32(INT_MAX);
2907 p.writeInt32(INT_MAX);
2908 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002909 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002910 }
johnwangfdf825f2009-05-22 15:50:34 -07002911
2912 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002913 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002914 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2915 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2916 EVDO_SS.signalNoiseRatio=%d,\
2917 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002918 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002919 printBuf,
2920 p_cur->GW_SignalStrength.signalStrength,
2921 p_cur->GW_SignalStrength.bitErrorRate,
2922 p_cur->CDMA_SignalStrength.dbm,
2923 p_cur->CDMA_SignalStrength.ecio,
2924 p_cur->EVDO_SignalStrength.dbm,
2925 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002926 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2927 p_cur->LTE_SignalStrength.signalStrength,
2928 p_cur->LTE_SignalStrength.rsrp,
2929 p_cur->LTE_SignalStrength.rsrq,
2930 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002931 p_cur->LTE_SignalStrength.cqi,
2932 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002933 closeResponse;
2934
Wink Saville3d54e742009-05-18 18:00:44 -07002935 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002936 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002937 return RIL_ERRNO_INVALID_RESPONSE;
2938 }
2939
Wink Saville3d54e742009-05-18 18:00:44 -07002940 return 0;
2941}
2942
2943static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2944 if ((response == NULL) || (responselen == 0)) {
2945 return responseVoid(p, response, responselen);
2946 } else {
2947 return responseCdmaSignalInfoRecord(p, response, responselen);
2948 }
2949}
2950
2951static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2952 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002953 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002954 return RIL_ERRNO_INVALID_RESPONSE;
2955 }
2956
2957 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002958 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002959 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2960 return RIL_ERRNO_INVALID_RESPONSE;
2961 }
2962
2963 startResponse;
2964
2965 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2966 marshallSignalInfoRecord(p, *p_cur);
2967
2968 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2969 signal=%d]",
2970 printBuf,
2971 p_cur->isPresent,
2972 p_cur->signalType,
2973 p_cur->alertPitch,
2974 p_cur->signal);
2975
2976 closeResponse;
2977 return 0;
2978}
2979
Wink Savillea592eeb2009-05-22 13:26:36 -07002980static int responseCdmaCallWaiting(Parcel &p, void *response,
2981 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002982 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002983 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002984 return RIL_ERRNO_INVALID_RESPONSE;
2985 }
2986
Wink Savillec0114b32011-02-18 10:14:07 -08002987 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002988 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002989 }
2990
2991 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2992
2993 writeStringToParcel(p, p_cur->number);
2994 p.writeInt32(p_cur->numberPresentation);
2995 writeStringToParcel(p, p_cur->name);
2996 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2997
2998 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2999 p.writeInt32(p_cur->number_type);
3000 p.writeInt32(p_cur->number_plan);
3001 } else {
3002 p.writeInt32(0);
3003 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003004 }
3005
3006 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003007 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3008 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003009 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003010 printBuf,
3011 p_cur->number,
3012 p_cur->numberPresentation,
3013 p_cur->name,
3014 p_cur->signalInfoRecord.isPresent,
3015 p_cur->signalInfoRecord.signalType,
3016 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003017 p_cur->signalInfoRecord.signal,
3018 p_cur->number_type,
3019 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003020 closeResponse;
3021
3022 return 0;
3023}
3024
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003025static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3026 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003027 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003028 return RIL_ERRNO_INVALID_RESPONSE;
3029 }
3030
3031 startResponse;
3032 if (s_callbacks.version == 7) {
3033 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3034 p.writeInt32(p_cur->result);
3035 p.writeInt32(p_cur->ef_id);
3036 writeStringToParcel(p, p_cur->aid);
3037
3038 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3039 printBuf,
3040 p_cur->result,
3041 p_cur->ef_id,
3042 p_cur->aid);
3043 } else {
3044 int *p_cur = ((int *) response);
3045 p.writeInt32(p_cur[0]);
3046 p.writeInt32(p_cur[1]);
3047 writeStringToParcel(p, NULL);
3048
3049 appendPrintBuf("%sresult=%d, ef_id=%d",
3050 printBuf,
3051 p_cur[0],
3052 p_cur[1]);
3053 }
3054 closeResponse;
3055
3056 return 0;
3057}
3058
Wink Saville8a9e0212013-04-09 12:11:38 -07003059static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3060{
3061 if (response == NULL && responselen != 0) {
3062 RLOGE("invalid response: NULL");
3063 return RIL_ERRNO_INVALID_RESPONSE;
3064 }
3065
3066 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003067 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003068 (int)responselen, (int)sizeof(RIL_CellInfo));
3069 return RIL_ERRNO_INVALID_RESPONSE;
3070 }
3071
3072 int num = responselen / sizeof(RIL_CellInfo);
3073 p.writeInt32(num);
3074
3075 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3076 startResponse;
3077 int i;
3078 for (i = 0; i < num; i++) {
3079 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3080 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3081 p.writeInt32((int)p_cur->cellInfoType);
3082 p.writeInt32(p_cur->registered);
3083 p.writeInt32(p_cur->timeStampType);
3084 p.writeInt64(p_cur->timeStamp);
3085 switch(p_cur->cellInfoType) {
3086 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003087 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003088 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3089 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3090 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003091 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3092 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003093 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3094 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3095
3096 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3097 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3098 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3099 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003100 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3101 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3102 break;
3103 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003104 case RIL_CELL_INFO_TYPE_WCDMA: {
3105 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3106 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3107 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3108 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3109 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3110 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3111 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3112 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3113 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3114
3115 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3116 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3117 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3118 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3119 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3120 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3121 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3122 break;
3123 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003124 case RIL_CELL_INFO_TYPE_CDMA: {
3125 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3126 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3127 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3128 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3129 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3130 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3131
3132 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3133 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3134 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3135 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3136 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3137
3138 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3139 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3140 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3141 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3142 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3143 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3144
3145 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3146 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3147 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3148 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3149 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3150 break;
3151 }
3152 case RIL_CELL_INFO_TYPE_LTE: {
3153 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3154 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3155 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3156 p_cur->CellInfo.lte.cellIdentityLte.ci,
3157 p_cur->CellInfo.lte.cellIdentityLte.pci,
3158 p_cur->CellInfo.lte.cellIdentityLte.tac);
3159
3160 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3161 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3162 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3163 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3164 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3165
3166 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3167 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3168 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3169 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3170 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3171 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3172 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3173 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3174 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3175 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3176 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3177 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3178 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3179 break;
3180 }
Etan Cohend3652192014-06-20 08:28:44 -07003181 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3182 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3183 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3184 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3185 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3186 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3187 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3188 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3189 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3190
3191 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3192 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3193 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3194 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3195 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3196 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3197 break;
3198 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003199 }
3200 p_cur += 1;
3201 }
3202 removeLastChar;
3203 closeResponse;
3204
3205 return 0;
3206}
3207
Etan Cohend3652192014-06-20 08:28:44 -07003208static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3209{
3210 if (response == NULL && responselen != 0) {
3211 RLOGE("invalid response: NULL");
3212 return RIL_ERRNO_INVALID_RESPONSE;
3213 }
3214
3215 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003216 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003217 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3218 return RIL_ERRNO_INVALID_RESPONSE;
3219 }
3220
3221 int num = responselen / sizeof(RIL_HardwareConfig);
3222 int i;
3223 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3224
3225 p.writeInt32(num);
3226
3227 startResponse;
3228 for (i = 0; i < num; i++) {
3229 switch (p_cur[i].type) {
3230 case RIL_HARDWARE_CONFIG_MODEM: {
3231 writeStringToParcel(p, p_cur[i].uuid);
3232 p.writeInt32((int)p_cur[i].state);
3233 p.writeInt32(p_cur[i].cfg.modem.rat);
3234 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3235 p.writeInt32(p_cur[i].cfg.modem.maxData);
3236 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3237
3238 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3239 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3240 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3241 break;
3242 }
3243 case RIL_HARDWARE_CONFIG_SIM: {
3244 writeStringToParcel(p, p_cur[i].uuid);
3245 p.writeInt32((int)p_cur[i].state);
3246 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3247
3248 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3249 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3250 break;
3251 }
3252 }
3253 }
3254 removeLastChar;
3255 closeResponse;
3256 return 0;
3257}
3258
Wink Saville8b4e4f72014-10-17 15:01:45 -07003259static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3260 if (response == NULL) {
3261 RLOGE("invalid response: NULL");
3262 return RIL_ERRNO_INVALID_RESPONSE;
3263 }
3264
3265 if (responselen != sizeof (RIL_RadioCapability) ) {
3266 RLOGE("invalid response length was %d expected %d",
3267 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3268 return RIL_ERRNO_INVALID_RESPONSE;
3269 }
3270
3271 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3272 p.writeInt32(p_cur->version);
3273 p.writeInt32(p_cur->session);
3274 p.writeInt32(p_cur->phase);
3275 p.writeInt32(p_cur->rat);
3276 writeStringToParcel(p, p_cur->logicalModemUuid);
3277 p.writeInt32(p_cur->status);
3278
3279 startResponse;
3280 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003281 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003282 printBuf,
3283 p_cur->version,
3284 p_cur->session,
3285 p_cur->phase,
3286 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003287 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003288 p_cur->status);
3289 closeResponse;
3290 return 0;
3291}
3292
Wink Saville3d54e742009-05-18 18:00:44 -07003293static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003294 int ret;
3295 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3296 /* trigger event loop to wakeup. No reason to do this,
3297 * if we're in the event loop thread */
3298 do {
3299 ret = write (s_fdWakeupWrite, " ", 1);
3300 } while (ret < 0 && errno == EINTR);
3301 }
3302}
3303
Wink Saville3d54e742009-05-18 18:00:44 -07003304static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003305 ril_event_add(ev);
3306 triggerEvLoop();
3307}
3308
Wink Savillefd729372011-02-22 16:19:39 -08003309static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3310 p.writeInt32(num_apps);
3311 startResponse;
3312 for (int i = 0; i < num_apps; i++) {
3313 p.writeInt32(appStatus[i].app_type);
3314 p.writeInt32(appStatus[i].app_state);
3315 p.writeInt32(appStatus[i].perso_substate);
3316 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3317 writeStringToParcel(p, (const char*)
3318 (appStatus[i].app_label_ptr));
3319 p.writeInt32(appStatus[i].pin1_replaced);
3320 p.writeInt32(appStatus[i].pin1);
3321 p.writeInt32(appStatus[i].pin2);
3322 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3323 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3324 printBuf,
3325 appStatus[i].app_type,
3326 appStatus[i].app_state,
3327 appStatus[i].perso_substate,
3328 appStatus[i].aid_ptr,
3329 appStatus[i].app_label_ptr,
3330 appStatus[i].pin1_replaced,
3331 appStatus[i].pin1,
3332 appStatus[i].pin2);
3333 }
3334 closeResponse;
3335}
3336
Wink Savillef4c4d362009-04-02 01:37:03 -07003337static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3338 int i;
3339
3340 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003341 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003342 return RIL_ERRNO_INVALID_RESPONSE;
3343 }
3344
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003345 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003346 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003347
Wink Savillefd729372011-02-22 16:19:39 -08003348 p.writeInt32(p_cur->card_state);
3349 p.writeInt32(p_cur->universal_pin_state);
3350 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3351 p.writeInt32(p_cur->cdma_subscription_app_index);
3352 p.writeInt32(p_cur->ims_subscription_app_index);
3353
3354 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003355 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003356 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3357
3358 p.writeInt32(p_cur->card_state);
3359 p.writeInt32(p_cur->universal_pin_state);
3360 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3361 p.writeInt32(p_cur->cdma_subscription_app_index);
3362 p.writeInt32(-1);
3363
3364 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003365 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003366 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003367 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003368 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003369
3370 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003371}
Wink Savillef4c4d362009-04-02 01:37:03 -07003372
Wink Savillea592eeb2009-05-22 13:26:36 -07003373static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3374 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003375 p.writeInt32(num);
3376
Wink Savillef4c4d362009-04-02 01:37:03 -07003377 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003378 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3379 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3380 for (int i = 0; i < num; i++) {
3381 p.writeInt32(p_cur[i]->fromServiceId);
3382 p.writeInt32(p_cur[i]->toServiceId);
3383 p.writeInt32(p_cur[i]->fromCodeScheme);
3384 p.writeInt32(p_cur[i]->toCodeScheme);
3385 p.writeInt32(p_cur[i]->selected);
3386
3387 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3388 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3389 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3390 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3391 p_cur[i]->selected);
3392 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003393 closeResponse;
3394
3395 return 0;
3396}
3397
Wink Savillea592eeb2009-05-22 13:26:36 -07003398static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3399 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3400 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003401
Wink Savillea592eeb2009-05-22 13:26:36 -07003402 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3403 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003404
3405 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003406 for (int i = 0 ; i < num ; i++ ) {
3407 p.writeInt32(p_cur[i]->service_category);
3408 p.writeInt32(p_cur[i]->language);
3409 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003410
Wink Savillea592eeb2009-05-22 13:26:36 -07003411 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3412 selected =%d], ",
3413 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3414 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003415 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003416 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003417
Wink Savillef4c4d362009-04-02 01:37:03 -07003418 return 0;
3419}
3420
3421static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3422 int num;
3423 int digitCount;
3424 int digitLimit;
3425 uint8_t uct;
3426 void* dest;
3427
Wink Saville8eb2a122012-11-19 16:05:13 -08003428 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003429
Wink Savillef4c4d362009-04-02 01:37:03 -07003430 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003431 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003432 return RIL_ERRNO_INVALID_RESPONSE;
3433 }
3434
Wink Savillef5903df2009-04-24 11:54:14 -07003435 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003436 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003437 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003438 return RIL_ERRNO_INVALID_RESPONSE;
3439 }
3440
3441 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3442 p.writeInt32(p_cur->uTeleserviceID);
3443 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3444 p.writeInt32(p_cur->uServicecategory);
3445 p.writeInt32(p_cur->sAddress.digit_mode);
3446 p.writeInt32(p_cur->sAddress.number_mode);
3447 p.writeInt32(p_cur->sAddress.number_type);
3448 p.writeInt32(p_cur->sAddress.number_plan);
3449 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3450 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3451 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3452 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3453 }
3454
3455 p.writeInt32(p_cur->sSubAddress.subaddressType);
3456 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3457 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3458 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3459 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3460 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3461 }
3462
3463 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3464 p.writeInt32(p_cur->uBearerDataLen);
3465 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3466 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3467 }
3468
3469 startResponse;
3470 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003471 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003472 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3473 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3474 closeResponse;
3475
3476 return 0;
3477}
3478
Wink Savillec29360a2014-07-13 05:17:28 -07003479static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3480{
3481 int num = responselen / sizeof(RIL_DcRtInfo);
3482 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003483 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003484 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3485 return RIL_ERRNO_INVALID_RESPONSE;
3486 }
3487
3488 startResponse;
3489 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3490 p.writeInt64(pDcRtInfo->time);
3491 p.writeInt32(pDcRtInfo->powerState);
3492 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3493 pDcRtInfo->time,
3494 pDcRtInfo->powerState);
3495 closeResponse;
3496
3497 return 0;
3498}
3499
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003500/**
3501 * A write on the wakeup fd is done just to pop us out of select()
3502 * We empty the buffer here and then ril_event will reset the timers on the
3503 * way back down
3504 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003505static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003506 char buff[16];
3507 int ret;
3508
Wink Saville8eb2a122012-11-19 16:05:13 -08003509 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003510
3511 /* empty our wakeup socket out */
3512 do {
3513 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003514 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003515}
3516
Etan Cohend3652192014-06-20 08:28:44 -07003517static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003518 int ret;
3519 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003520 /* Hook for current context
3521 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3522 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3523 /* pendingRequestsHook refer to &s_pendingRequests */
3524 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003525
Etan Cohend3652192014-06-20 08:28:44 -07003526#if (SIM_COUNT >= 2)
3527 if (socket_id == RIL_SOCKET_2) {
3528 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3529 pendingRequestsHook = &s_pendingRequests_socket2;
3530 }
3531#if (SIM_COUNT >= 3)
3532 else if (socket_id == RIL_SOCKET_3) {
3533 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3534 pendingRequestsHook = &s_pendingRequests_socket3;
3535 }
3536#endif
3537#if (SIM_COUNT >= 4)
3538 else if (socket_id == RIL_SOCKET_4) {
3539 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3540 pendingRequestsHook = &s_pendingRequests_socket4;
3541 }
3542#endif
3543#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003544 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003545 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003546 assert (ret == 0);
3547
Etan Cohend3652192014-06-20 08:28:44 -07003548 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003549
Etan Cohend3652192014-06-20 08:28:44 -07003550 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003551 ; p_cur != NULL
3552 ; p_cur = p_cur->p_next
3553 ) {
3554 p_cur->cancelled = 1;
3555 }
3556
Etan Cohend3652192014-06-20 08:28:44 -07003557 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003558 assert (ret == 0);
3559}
3560
Wink Savillef4c4d362009-04-02 01:37:03 -07003561static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003562 RecordStream *p_rs;
3563 void *p_record;
3564 size_t recordlen;
3565 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003566 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003567
Etan Cohend3652192014-06-20 08:28:44 -07003568 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003569
Etan Cohend3652192014-06-20 08:28:44 -07003570 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003571
3572 for (;;) {
3573 /* loop until EAGAIN/EINTR, end of stream, or other error */
3574 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3575
3576 if (ret == 0 && p_record == NULL) {
3577 /* end-of-stream */
3578 break;
3579 } else if (ret < 0) {
3580 break;
3581 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003582 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003583 }
3584 }
3585
3586 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3587 /* fatal error or end-of-stream */
3588 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003589 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003590 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003591 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003592 }
Wink Saville7f856802009-06-09 10:23:37 -07003593
Etan Cohend3652192014-06-20 08:28:44 -07003594 close(fd);
3595 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003596
Etan Cohend3652192014-06-20 08:28:44 -07003597 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003598
3599 record_stream_free(p_rs);
3600
3601 /* start listening for new connections again */
3602 rilEventAddWakeup(&s_listen_event);
3603
Etan Cohend3652192014-06-20 08:28:44 -07003604 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003605 }
3606}
3607
3608
Etan Cohend3652192014-06-20 08:28:44 -07003609static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003610 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003611 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003612 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3613 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003614
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003615 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003616 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3617 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003618
3619 // Send last NITZ time data, in case it was missed
3620 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003621 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003622
3623 free(s_lastNITZTimeData);
3624 s_lastNITZTimeData = NULL;
3625 }
3626
3627 // Get version string
3628 if (s_callbacks.getVersion != NULL) {
3629 const char *version;
3630 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003631 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003632
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003633 property_set(PROPERTY_RIL_IMPL, version);
3634 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003635 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003636 property_set(PROPERTY_RIL_IMPL, "unavailable");
3637 }
3638
3639}
3640
Wink Savillef4c4d362009-04-02 01:37:03 -07003641static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003642 int ret;
3643 int err;
3644 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003645 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003646 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003647 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003648
3649 struct sockaddr_un peeraddr;
3650 socklen_t socklen = sizeof (peeraddr);
3651
3652 struct ucred creds;
3653 socklen_t szCreds = sizeof(creds);
3654
3655 struct passwd *pwd = NULL;
3656
Etan Cohend3652192014-06-20 08:28:44 -07003657 assert (*p_info->fdCommand < 0);
3658 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003659
Etan Cohend3652192014-06-20 08:28:44 -07003660 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003661
Etan Cohend3652192014-06-20 08:28:44 -07003662 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003663 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003664 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003665 rilEventAddWakeup(p_info->listen_event);
3666 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003667 }
3668
3669 /* check the credential of the other side and only accept socket from
3670 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003671 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672 errno = 0;
3673 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003674
Etan Cohend3652192014-06-20 08:28:44 -07003675 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003676
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003677 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003678 errno = 0;
3679 pwd = getpwuid(creds.uid);
3680 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003681 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003682 is_phone_socket = 1;
3683 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003684 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003685 }
3686 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003687 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003688 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003689 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003690 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003691 }
3692
Etan Cohend3652192014-06-20 08:28:44 -07003693 if (!is_phone_socket) {
3694 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003695
Etan Cohend3652192014-06-20 08:28:44 -07003696 close(fdCommand);
3697 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003698
Etan Cohend3652192014-06-20 08:28:44 -07003699 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003700
3701 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003702 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003703
3704 return;
3705 }
3706
Etan Cohend3652192014-06-20 08:28:44 -07003707 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003708
3709 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003710 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003711 }
3712
Etan Cohend3652192014-06-20 08:28:44 -07003713 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003714
Etan Cohend3652192014-06-20 08:28:44 -07003715 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003716
Etan Cohend3652192014-06-20 08:28:44 -07003717 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003718
Etan Cohend3652192014-06-20 08:28:44 -07003719 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003720
Etan Cohend3652192014-06-20 08:28:44 -07003721 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3722 p_info->processCommandsCallback, p_info);
3723
3724 rilEventAddWakeup (p_info->commands_event);
3725
3726 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003727}
3728
3729static void freeDebugCallbackArgs(int number, char **args) {
3730 for (int i = 0; i < number; i++) {
3731 if (args[i] != NULL) {
3732 free(args[i]);
3733 }
3734 }
3735 free(args);
3736}
3737
Wink Savillef4c4d362009-04-02 01:37:03 -07003738static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003739 int acceptFD, option;
3740 struct sockaddr_un peeraddr;
3741 socklen_t socklen = sizeof (peeraddr);
3742 int data;
3743 unsigned int qxdm_data[6];
3744 const char *deactData[1] = {"1"};
3745 char *actData[1];
3746 RIL_Dial dialData;
3747 int hangupData[1] = {1};
3748 int number;
3749 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003750 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3751 int sim_id = 0;
3752
3753 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003754
3755 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3756
3757 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003758 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003759 return;
3760 }
3761
3762 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003763 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003764 return;
3765 }
3766 args = (char **) malloc(sizeof(char*) * number);
3767
3768 for (int i = 0; i < number; i++) {
3769 int len;
3770 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003771 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003772 freeDebugCallbackArgs(i, args);
3773 return;
3774 }
3775 // +1 for null-term
3776 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003777 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003778 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003779 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003780 freeDebugCallbackArgs(i, args);
3781 return;
3782 }
3783 char * buf = args[i];
3784 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003785 if ((i+1) == number) {
3786 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3787 sim_id = atoi(args[i]);
3788 switch (sim_id) {
3789 case 0:
3790 socket_id = RIL_SOCKET_1;
3791 break;
3792 #if (SIM_COUNT >= 2)
3793 case 1:
3794 socket_id = RIL_SOCKET_2;
3795 break;
3796 #endif
3797 #if (SIM_COUNT >= 3)
3798 case 2:
3799 socket_id = RIL_SOCKET_3;
3800 break;
3801 #endif
3802 #if (SIM_COUNT >= 4)
3803 case 3:
3804 socket_id = RIL_SOCKET_4;
3805 break;
3806 #endif
3807 default:
3808 socket_id = RIL_SOCKET_1;
3809 break;
3810 }
3811 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003812 }
3813
3814 switch (atoi(args[0])) {
3815 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003816 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003817 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003818 break;
3819 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003820 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003821 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003822 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003823 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003824 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3825 close(s_ril_param_socket.fdCommand);
3826 s_ril_param_socket.fdCommand = -1;
3827 }
3828 #if (SIM_COUNT == 2)
3829 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3830 close(s_ril_param_socket2.fdCommand);
3831 s_ril_param_socket2.fdCommand = -1;
3832 }
3833 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003834 break;
3835 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003836 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003837 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003838 break;
3839 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003840 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003841 qxdm_data[0] = 65536; // head.func_tag
3842 qxdm_data[1] = 16; // head.len
3843 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3844 qxdm_data[3] = 32; // log_file_size: 32megabytes
3845 qxdm_data[4] = 0; // log_mask
3846 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003847 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003848 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003849 break;
3850 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003851 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003852 qxdm_data[0] = 65536;
3853 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003854 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003855 qxdm_data[3] = 32;
3856 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003857 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003858 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003859 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003860 break;
3861 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003862 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003863 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003864 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003865 sleep(2);
3866 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003867 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003868 break;
3869 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003870 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003871 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003872 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003873 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003874 break;
3875 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003876 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003877 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003878 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003879 break;
3880 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003881 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003882 dialData.clir = 0;
3883 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003884 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003885 break;
3886 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003887 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003888 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003889 break;
3890 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003891 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003892 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003893 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003894 break;
3895 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003896 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003897 break;
3898 }
3899 freeDebugCallbackArgs(number, args);
3900 close(acceptFD);
3901}
3902
3903
Wink Savillef4c4d362009-04-02 01:37:03 -07003904static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003905 UserCallbackInfo *p_info;
3906
3907 p_info = (UserCallbackInfo *)param;
3908
3909 p_info->p_callback(p_info->userParam);
3910
3911
3912 // FIXME generalize this...there should be a cancel mechanism
3913 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3914 s_last_wake_timeout_info = NULL;
3915 }
3916
3917 free(p_info);
3918}
3919
3920
3921static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003922eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003923 int ret;
3924 int filedes[2];
3925
3926 ril_event_init();
3927
3928 pthread_mutex_lock(&s_startupMutex);
3929
3930 s_started = 1;
3931 pthread_cond_broadcast(&s_startupCond);
3932
3933 pthread_mutex_unlock(&s_startupMutex);
3934
3935 ret = pipe(filedes);
3936
3937 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003938 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003939 return NULL;
3940 }
3941
3942 s_fdWakeupRead = filedes[0];
3943 s_fdWakeupWrite = filedes[1];
3944
3945 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3946
3947 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3948 processWakeupCallback, NULL);
3949
3950 rilEventAddWakeup (&s_wakeupfd_event);
3951
3952 // Only returns on error
3953 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003954 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003955 // kill self to restart on error
3956 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003957
3958 return NULL;
3959}
3960
Wink Saville7f856802009-06-09 10:23:37 -07003961extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003962RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003963 /* spin up eventLoop thread and wait for it to get started */
3964 s_started = 0;
3965 pthread_mutex_lock(&s_startupMutex);
3966
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003967 pthread_attr_t attr;
3968 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003969 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003970
Elliott Hughesfd81e712014-01-06 12:46:02 -08003971 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3972 if (result != 0) {
3973 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003974 goto done;
3975 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003976
3977 while (s_started == 0) {
3978 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3979 }
3980
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003981done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003982 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003983}
3984
3985// Used for testing purpose only.
3986extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3987 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3988}
3989
Etan Cohend3652192014-06-20 08:28:44 -07003990static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3991 int fdListen = -1;
3992 int ret;
3993 char socket_name[10];
3994
3995 memset(socket_name, 0, sizeof(char)*10);
3996
3997 switch(socket_id) {
3998 case RIL_SOCKET_1:
3999 strncpy(socket_name, RIL_getRilSocketName(), 9);
4000 break;
4001 #if (SIM_COUNT >= 2)
4002 case RIL_SOCKET_2:
4003 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4004 break;
4005 #endif
4006 #if (SIM_COUNT >= 3)
4007 case RIL_SOCKET_3:
4008 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4009 break;
4010 #endif
4011 #if (SIM_COUNT >= 4)
4012 case RIL_SOCKET_4:
4013 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4014 break;
4015 #endif
4016 default:
4017 RLOGE("Socket id is wrong!!");
4018 return;
4019 }
4020
4021 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4022
4023 fdListen = android_get_control_socket(socket_name);
4024 if (fdListen < 0) {
4025 RLOGE("Failed to get socket %s", socket_name);
4026 exit(-1);
4027 }
4028
4029 ret = listen(fdListen, 4);
4030
4031 if (ret < 0) {
4032 RLOGE("Failed to listen on control socket '%d': %s",
4033 fdListen, strerror(errno));
4034 exit(-1);
4035 }
4036 socket_listen_p->fdListen = fdListen;
4037
4038 /* note: non-persistent so we can accept only one connection at a time */
4039 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4040 listenCallback, socket_listen_p);
4041
4042 rilEventAddWakeup (socket_listen_p->listen_event);
4043}
4044
Wink Saville7f856802009-06-09 10:23:37 -07004045extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004046RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004047 int ret;
4048 int flags;
4049
Etan Cohend3652192014-06-20 08:28:44 -07004050 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4051
Wink Saville43808972011-01-13 17:39:51 -08004052 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004053 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004054 return;
4055 }
Wink Saville43808972011-01-13 17:39:51 -08004056 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004057 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004058 callbacks->version, RIL_VERSION_MIN);
4059 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004060 }
Wink Saville43808972011-01-13 17:39:51 -08004061 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004062 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004063 callbacks->version, RIL_VERSION);
4064 return;
4065 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004066 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004067
4068 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004069 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004070 "Subsequent call ignored");
4071 return;
4072 }
4073
4074 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4075
Etan Cohend3652192014-06-20 08:28:44 -07004076 /* Initialize socket1 parameters */
4077 s_ril_param_socket = {
4078 RIL_SOCKET_1, /* socket_id */
4079 -1, /* fdListen */
4080 -1, /* fdCommand */
4081 PHONE_PROCESS, /* processName */
4082 &s_commands_event, /* commands_event */
4083 &s_listen_event, /* listen_event */
4084 processCommandsCallback, /* processCommandsCallback */
4085 NULL /* p_rs */
4086 };
4087
4088#if (SIM_COUNT >= 2)
4089 s_ril_param_socket2 = {
4090 RIL_SOCKET_2, /* socket_id */
4091 -1, /* fdListen */
4092 -1, /* fdCommand */
4093 PHONE_PROCESS, /* processName */
4094 &s_commands_event_socket2, /* commands_event */
4095 &s_listen_event_socket2, /* listen_event */
4096 processCommandsCallback, /* processCommandsCallback */
4097 NULL /* p_rs */
4098 };
4099#endif
4100
4101#if (SIM_COUNT >= 3)
4102 s_ril_param_socket3 = {
4103 RIL_SOCKET_3, /* socket_id */
4104 -1, /* fdListen */
4105 -1, /* fdCommand */
4106 PHONE_PROCESS, /* processName */
4107 &s_commands_event_socket3, /* commands_event */
4108 &s_listen_event_socket3, /* listen_event */
4109 processCommandsCallback, /* processCommandsCallback */
4110 NULL /* p_rs */
4111 };
4112#endif
4113
4114#if (SIM_COUNT >= 4)
4115 s_ril_param_socket4 = {
4116 RIL_SOCKET_4, /* socket_id */
4117 -1, /* fdListen */
4118 -1, /* fdCommand */
4119 PHONE_PROCESS, /* processName */
4120 &s_commands_event_socket4, /* commands_event */
4121 &s_listen_event_socket4, /* listen_event */
4122 processCommandsCallback, /* processCommandsCallback */
4123 NULL /* p_rs */
4124 };
4125#endif
4126
4127
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004128 s_registerCalled = 1;
4129
Etan Cohend3652192014-06-20 08:28:44 -07004130 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004131 // Little self-check
4132
Wink Savillef4c4d362009-04-02 01:37:03 -07004133 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004134 assert(i == s_commands[i].requestNumber);
4135 }
4136
Wink Savillef4c4d362009-04-02 01:37:03 -07004137 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004138 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004139 == s_unsolResponses[i].requestNumber);
4140 }
4141
4142 // New rild impl calls RIL_startEventLoop() first
4143 // old standalone impl wants it here.
4144
4145 if (s_started == 0) {
4146 RIL_startEventLoop();
4147 }
4148
Etan Cohend3652192014-06-20 08:28:44 -07004149 // start listen socket1
4150 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004151
Etan Cohend3652192014-06-20 08:28:44 -07004152#if (SIM_COUNT >= 2)
4153 // start listen socket2
4154 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4155#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004156
Etan Cohend3652192014-06-20 08:28:44 -07004157#if (SIM_COUNT >= 3)
4158 // start listen socket3
4159 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4160#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004161
Etan Cohend3652192014-06-20 08:28:44 -07004162#if (SIM_COUNT >= 4)
4163 // start listen socket4
4164 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4165#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004166
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004167
4168#if 1
4169 // start debug interface socket
4170
Etan Cohend3652192014-06-20 08:28:44 -07004171 char *inst = NULL;
4172 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4173 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4174 }
4175
4176 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4177 if (inst != NULL) {
4178 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4179 }
4180
4181 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004182 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004183 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004184 exit(-1);
4185 }
4186
4187 ret = listen(s_fdDebug, 4);
4188
4189 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004190 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004191 s_fdDebug, strerror(errno));
4192 exit(-1);
4193 }
4194
4195 ril_event_set (&s_debug_event, s_fdDebug, true,
4196 debugCallback, NULL);
4197
4198 rilEventAddWakeup (&s_debug_event);
4199#endif
4200
4201}
4202
4203static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004204checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004205 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004206 /* Hook for current context
4207 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4208 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4209 /* pendingRequestsHook refer to &s_pendingRequests */
4210 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004211
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004212 if (pRI == NULL) {
4213 return 0;
4214 }
4215
Etan Cohend3652192014-06-20 08:28:44 -07004216#if (SIM_COUNT >= 2)
4217 if (pRI->socket_id == RIL_SOCKET_2) {
4218 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4219 pendingRequestsHook = &s_pendingRequests_socket2;
4220 }
4221#if (SIM_COUNT >= 3)
4222 if (pRI->socket_id == RIL_SOCKET_3) {
4223 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4224 pendingRequestsHook = &s_pendingRequests_socket3;
4225 }
4226#endif
4227#if (SIM_COUNT >= 4)
4228 if (pRI->socket_id == RIL_SOCKET_4) {
4229 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4230 pendingRequestsHook = &s_pendingRequests_socket4;
4231 }
4232#endif
4233#endif
4234 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235
Etan Cohend3652192014-06-20 08:28:44 -07004236 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004237 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004238 ; ppCur = &((*ppCur)->p_next)
4239 ) {
4240 if (pRI == *ppCur) {
4241 ret = 1;
4242
4243 *ppCur = (*ppCur)->p_next;
4244 break;
4245 }
4246 }
4247
Etan Cohend3652192014-06-20 08:28:44 -07004248 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004249
4250 return ret;
4251}
4252
4253
4254extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004255RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004256 RequestInfo *pRI;
4257 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004258 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004259 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004260 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004261
4262 pRI = (RequestInfo *)t;
4263
Jayachandran C6c607592014-08-04 15:48:01 -07004264 if (!checkAndDequeueRequestInfo(pRI)) {
4265 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4266 return;
4267 }
4268
Etan Cohend3652192014-06-20 08:28:44 -07004269 socket_id = pRI->socket_id;
4270#if (SIM_COUNT >= 2)
4271 if (socket_id == RIL_SOCKET_2) {
4272 fd = s_ril_param_socket2.fdCommand;
4273 }
4274#if (SIM_COUNT >= 3)
4275 if (socket_id == RIL_SOCKET_3) {
4276 fd = s_ril_param_socket3.fdCommand;
4277 }
4278#endif
4279#if (SIM_COUNT >= 4)
4280 if (socket_id == RIL_SOCKET_4) {
4281 fd = s_ril_param_socket4.fdCommand;
4282 }
4283#endif
4284#endif
4285 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4286
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004287 if (pRI->local > 0) {
4288 // Locally issued command...void only!
4289 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004290 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004291
4292 goto done;
4293 }
4294
4295 appendPrintBuf("[%04d]< %s",
4296 pRI->token, requestToString(pRI->pCI->requestNumber));
4297
4298 if (pRI->cancelled == 0) {
4299 Parcel p;
4300
4301 p.writeInt32 (RESPONSE_SOLICITED);
4302 p.writeInt32 (pRI->token);
4303 errorOffset = p.dataPosition();
4304
4305 p.writeInt32 (e);
4306
johnwangb2a61842009-06-02 14:55:45 -07004307 if (response != NULL) {
4308 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004309 ret = pRI->pCI->responseFunction(p, response, responselen);
4310
4311 /* if an error occurred, rewind and mark it */
4312 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004313 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004314 p.setDataPosition(errorOffset);
4315 p.writeInt32 (ret);
4316 }
johnwangb2a61842009-06-02 14:55:45 -07004317 }
4318
4319 if (e != RIL_E_SUCCESS) {
4320 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004321 }
4322
Etan Cohend3652192014-06-20 08:28:44 -07004323 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004324 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004325 }
Etan Cohend3652192014-06-20 08:28:44 -07004326 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004327 }
4328
4329done:
4330 free(pRI);
4331}
4332
4333
4334static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004335grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004336 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4337}
4338
4339static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004340releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004341 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4342}
4343
4344/**
4345 * Timer callback to put us back to sleep before the default timeout
4346 */
4347static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004348wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004349 // We're using "param != NULL" as a cancellation mechanism
4350 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004351 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004352
4353 releaseWakeLock();
4354 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004355 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004356 }
4357}
4358
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004359static int
4360decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4361 switch (radioState) {
4362 case RADIO_STATE_SIM_NOT_READY:
4363 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4364 case RADIO_STATE_SIM_READY:
4365 return RADIO_TECH_UMTS;
4366
4367 case RADIO_STATE_RUIM_NOT_READY:
4368 case RADIO_STATE_RUIM_READY:
4369 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4370 case RADIO_STATE_NV_NOT_READY:
4371 case RADIO_STATE_NV_READY:
4372 return RADIO_TECH_1xRTT;
4373
4374 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004375 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004376 return -1;
4377 }
4378}
4379
4380static int
4381decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4382 switch (radioState) {
4383 case RADIO_STATE_SIM_NOT_READY:
4384 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4385 case RADIO_STATE_SIM_READY:
4386 case RADIO_STATE_RUIM_NOT_READY:
4387 case RADIO_STATE_RUIM_READY:
4388 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4389 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4390
4391 case RADIO_STATE_NV_NOT_READY:
4392 case RADIO_STATE_NV_READY:
4393 return CDMA_SUBSCRIPTION_SOURCE_NV;
4394
4395 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004396 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004397 return -1;
4398 }
4399}
4400
4401static int
4402decodeSimStatus (RIL_RadioState radioState) {
4403 switch (radioState) {
4404 case RADIO_STATE_SIM_NOT_READY:
4405 case RADIO_STATE_RUIM_NOT_READY:
4406 case RADIO_STATE_NV_NOT_READY:
4407 case RADIO_STATE_NV_READY:
4408 return -1;
4409 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4410 case RADIO_STATE_SIM_READY:
4411 case RADIO_STATE_RUIM_READY:
4412 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4413 return radioState;
4414 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004415 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004416 return -1;
4417 }
4418}
4419
4420static bool is3gpp2(int radioTech) {
4421 switch (radioTech) {
4422 case RADIO_TECH_IS95A:
4423 case RADIO_TECH_IS95B:
4424 case RADIO_TECH_1xRTT:
4425 case RADIO_TECH_EVDO_0:
4426 case RADIO_TECH_EVDO_A:
4427 case RADIO_TECH_EVDO_B:
4428 case RADIO_TECH_EHRPD:
4429 return true;
4430 default:
4431 return false;
4432 }
4433}
4434
4435/* If RIL sends SIM states or RUIM states, store the voice radio
4436 * technology and subscription source information so that they can be
4437 * returned when telephony framework requests them
4438 */
4439static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004440processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004441
4442 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4443 int newVoiceRadioTech;
4444 int newCdmaSubscriptionSource;
4445 int newSimStatus;
4446
4447 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4448 from Radio State and send change notifications if there has been a change */
4449 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4450 if(newVoiceRadioTech != voiceRadioTech) {
4451 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004452 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4453 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004454 }
4455 if(is3gpp2(newVoiceRadioTech)) {
4456 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4457 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4458 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004459 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4460 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004461 }
4462 }
4463 newSimStatus = decodeSimStatus(newRadioState);
4464 if(newSimStatus != simRuimStatus) {
4465 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004466 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004467 }
4468
4469 /* Send RADIO_ON to telephony */
4470 newRadioState = RADIO_STATE_ON;
4471 }
4472
4473 return newRadioState;
4474}
4475
Etan Cohend3652192014-06-20 08:28:44 -07004476
4477#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004478extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004479void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4480 size_t datalen, RIL_SOCKET_ID socket_id)
4481#else
4482extern "C"
4483void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004484 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004485#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004486{
4487 int unsolResponseIndex;
4488 int ret;
4489 int64_t timeReceived = 0;
4490 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004491 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004492 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4493
4494#if defined(ANDROID_MULTI_SIM)
4495 soc_id = socket_id;
4496#endif
4497
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004498
4499 if (s_registerCalled == 0) {
4500 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004501 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004502 return;
4503 }
Wink Saville7f856802009-06-09 10:23:37 -07004504
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004505 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4506
4507 if ((unsolResponseIndex < 0)
4508 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004509 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004510 return;
4511 }
4512
4513 // Grab a wake lock if needed for this reponse,
4514 // as we exit we'll either release it immediately
4515 // or set a timer to release it later.
4516 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4517 case WAKE_PARTIAL:
4518 grabPartialWakeLock();
4519 shouldScheduleTimeout = true;
4520 break;
4521
4522 case DONT_WAKE:
4523 default:
4524 // No wake lock is grabed so don't set timeout
4525 shouldScheduleTimeout = false;
4526 break;
4527 }
4528
4529 // Mark the time this was received, doing this
4530 // after grabing the wakelock incase getting
4531 // the elapsedRealTime might cause us to goto
4532 // sleep.
4533 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4534 timeReceived = elapsedRealtime();
4535 }
4536
4537 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4538
4539 Parcel p;
4540
4541 p.writeInt32 (RESPONSE_UNSOLICITED);
4542 p.writeInt32 (unsolResponse);
4543
4544 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004545 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004546 if (ret != 0) {
4547 // Problem with the response. Don't continue;
4548 goto error_exit;
4549 }
4550
4551 // some things get more payload
4552 switch(unsolResponse) {
4553 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004554 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004555 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004556 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004557 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004558 break;
4559
4560
4561 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4562 // Store the time that this was received so the
4563 // handler of this message can account for
4564 // the time it takes to arrive and process. In
4565 // particular the system has been known to sleep
4566 // before this message can be processed.
4567 p.writeInt64(timeReceived);
4568 break;
4569 }
4570
Etan Cohend3652192014-06-20 08:28:44 -07004571 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4572 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004573 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4574
4575 // Unfortunately, NITZ time is not poll/update like everything
4576 // else in the system. So, if the upstream client isn't connected,
4577 // keep a copy of the last NITZ response (with receive time noted
4578 // above) around so we can deliver it when it is connected
4579
4580 if (s_lastNITZTimeData != NULL) {
4581 free (s_lastNITZTimeData);
4582 s_lastNITZTimeData = NULL;
4583 }
4584
4585 s_lastNITZTimeData = malloc(p.dataSize());
4586 s_lastNITZTimeDataSize = p.dataSize();
4587 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4588 }
4589
4590 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4591 // FIXME The java code should handshake here to release wake lock
4592
4593 if (shouldScheduleTimeout) {
4594 // Cancel the previous request
4595 if (s_last_wake_timeout_info != NULL) {
4596 s_last_wake_timeout_info->userParam = (void *)1;
4597 }
4598
4599 s_last_wake_timeout_info
4600 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4601 &TIMEVAL_WAKE_TIMEOUT);
4602 }
4603
4604 // Normal exit
4605 return;
4606
4607error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004608 if (shouldScheduleTimeout) {
4609 releaseWakeLock();
4610 }
4611}
4612
Wink Saville7f856802009-06-09 10:23:37 -07004613/** FIXME generalize this if you track UserCAllbackInfo, clear it
4614 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004615*/
4616static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004617internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004618 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004619{
4620 struct timeval myRelativeTime;
4621 UserCallbackInfo *p_info;
4622
4623 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4624
Wink Saville7f856802009-06-09 10:23:37 -07004625 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004626 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004627
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004628 if (relativeTime == NULL) {
4629 /* treat null parameter as a 0 relative time */
4630 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4631 } else {
4632 /* FIXME I think event_add's tv param is really const anyway */
4633 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4634 }
4635
4636 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4637
4638 ril_timer_add(&(p_info->event), &myRelativeTime);
4639
4640 triggerEvLoop();
4641 return p_info;
4642}
4643
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004644
4645extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004646RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4647 const struct timeval *relativeTime) {
4648 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004649}
4650
4651const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004652failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004653 switch(e) {
4654 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004655 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004656 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4657 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4658 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4659 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4660 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4661 case RIL_E_CANCELLED: return "E_CANCELLED";
4662 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4663 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4664 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004665 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004666 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004667#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004668 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4669 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4670#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004671 default: return "<unknown error>";
4672 }
4673}
4674
4675const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004676radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004677 switch(s) {
4678 case RADIO_STATE_OFF: return "RADIO_OFF";
4679 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4680 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4681 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4682 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004683 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4684 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4685 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4686 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4687 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004688 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004689 default: return "<unknown state>";
4690 }
4691}
4692
4693const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004694callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004695 switch(s) {
4696 case RIL_CALL_ACTIVE : return "ACTIVE";
4697 case RIL_CALL_HOLDING: return "HOLDING";
4698 case RIL_CALL_DIALING: return "DIALING";
4699 case RIL_CALL_ALERTING: return "ALERTING";
4700 case RIL_CALL_INCOMING: return "INCOMING";
4701 case RIL_CALL_WAITING: return "WAITING";
4702 default: return "<unknown state>";
4703 }
4704}
4705
4706const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004707requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004708/*
4709 cat libs/telephony/ril_commands.h \
4710 | egrep "^ *{RIL_" \
4711 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4712
4713
4714 cat libs/telephony/ril_unsol_commands.h \
4715 | egrep "^ *{RIL_" \
4716 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4717
4718*/
4719 switch(request) {
4720 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4721 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4722 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4723 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4724 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4725 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4726 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4727 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4728 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4729 case RIL_REQUEST_DIAL: return "DIAL";
4730 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4731 case RIL_REQUEST_HANGUP: return "HANGUP";
4732 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4733 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4734 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4735 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4736 case RIL_REQUEST_UDUB: return "UDUB";
4737 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4738 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004739 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4740 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004741 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4742 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4743 case RIL_REQUEST_DTMF: return "DTMF";
4744 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4745 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004746 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004747 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4748 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4749 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4750 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4751 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4752 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4753 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4754 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4755 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4756 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4757 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4758 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4759 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004760 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004761 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4762 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4763 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4764 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4765 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4766 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4767 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4768 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4769 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4770 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4771 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4772 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4773 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4774 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4775 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4776 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4777 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004778 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4779 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004780 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4781 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4782 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004783 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4784 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004785 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4786 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4787 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4788 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4789 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4790 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4791 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4792 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004793 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004794 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4795 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4796 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4797 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4798 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4799 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4800 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4801 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4802 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4803 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004804 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4805 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4806 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4807 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4808 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004809 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004810 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4811 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4812 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4813 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004814 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4815 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4816 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004817 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004818 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004819 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004820 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004821 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4822 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004823 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004824 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4825 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004826 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004827 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4828 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004829 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4830 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4831 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4832 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004833 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4834 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07004835 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4836 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004837 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4838 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004839 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4840 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004841 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004842 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4843 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004844 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 -08004845 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4846 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4847 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4848 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4849 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4850 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4851 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4852 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4853 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4854 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4855 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4856 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4857 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004858 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004859 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004860 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4861 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4862 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4863 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004864 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4865 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4866 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4867 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4868 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004869 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004870 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004871 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004872 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004873 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4874 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004875 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004876 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004877 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004878 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004879 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4880 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4881 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004882 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07004883 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004884 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004885 default: return "<unknown request>";
4886 }
4887}
4888
Etan Cohend3652192014-06-20 08:28:44 -07004889const char *
4890rilSocketIdToString(RIL_SOCKET_ID socket_id)
4891{
4892 switch(socket_id) {
4893 case RIL_SOCKET_1:
4894 return "RIL_SOCKET_1";
4895#if (SIM_COUNT >= 2)
4896 case RIL_SOCKET_2:
4897 return "RIL_SOCKET_2";
4898#endif
4899#if (SIM_COUNT >= 3)
4900 case RIL_SOCKET_3:
4901 return "RIL_SOCKET_3";
4902#endif
4903#if (SIM_COUNT >= 4)
4904 case RIL_SOCKET_4:
4905 return "RIL_SOCKET_4";
4906#endif
4907 default:
4908 return "not a valid RIL";
4909 }
4910}
4911
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004912} /* namespace android */