blob: f526294a6114f14ebc1e8a1cc96c6278703cbba0 [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);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800279static int responseInts(Parcel &p, void *response, size_t responselen);
280static int responseStrings(Parcel &p, void *response, size_t responselen);
281static int responseString(Parcel &p, void *response, size_t responselen);
282static int responseVoid(Parcel &p, void *response, size_t responselen);
283static int responseCallList(Parcel &p, void *response, size_t responselen);
284static int responseSMS(Parcel &p, void *response, size_t responselen);
285static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
286static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700287static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800288static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800289static int responseRaw(Parcel &p, void *response, size_t responselen);
290static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700291static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700292static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
293static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700294static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800295static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700296static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
297static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
298static int responseCallRing(Parcel &p, void *response, size_t responselen);
299static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
300static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800301static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700302static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700303static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700304static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800305
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800306static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
307static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
308static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
309
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800310#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700311#if defined(ANDROID_MULTI_SIM)
312extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
313 size_t datalen, RIL_SOCKET_ID socket_id);
314#else
Wink Saville7f856802009-06-09 10:23:37 -0700315extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316 size_t datalen);
317#endif
Etan Cohend3652192014-06-20 08:28:44 -0700318#endif
319
320#if defined(ANDROID_MULTI_SIM)
321#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
322#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
323#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
324#else
325#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
326#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
327#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
328#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800329
Wink Saville7f856802009-06-09 10:23:37 -0700330static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700331 (RIL_TimedCallback callback, void *param,
332 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800333
334/** Index == requestNumber */
335static CommandInfo s_commands[] = {
336#include "ril_commands.h"
337};
338
339static UnsolResponseInfo s_unsolResponses[] = {
340#include "ril_unsol_commands.h"
341};
342
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800343/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
344 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
345 radio state message and store it. Every time there is a change in Radio State
346 check to see if voice radio tech changes and notify telephony
347 */
348int voiceRadioTech = -1;
349
350/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
351 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
352 source from radio state and store it. Every time there is a change in Radio State
353 check to see if subscription source changed and notify telephony
354 */
355int cdmaSubscriptionSource = -1;
356
357/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
358 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
359 check to see if SIM/RUIM status changed and notify telephony
360 */
361int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800362
Etan Cohend3652192014-06-20 08:28:44 -0700363static char * RIL_getRilSocketName() {
364 return rild;
365}
366
367extern "C"
368void RIL_setRilSocketName(char * s) {
369 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
370}
371
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800372static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700373strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800374 size_t stringlen;
375 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700376
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800377 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700378
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 return strndup16to8(s16, stringlen);
380}
381
Wink Savillef4c4d362009-04-02 01:37:03 -0700382static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800383 char16_t *s16;
384 size_t s16_len;
385 s16 = strdup8to16(s, &s16_len);
386 p.writeString16(s16, s16_len);
387 free(s16);
388}
389
390
391static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700392memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800393 if (s != NULL) {
394 memset (s, 0, strlen(s));
395 }
396}
397
398void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
399 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700400 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800401 // do nothing -- the data reference lives longer than the Parcel object
402}
403
Wink Saville7f856802009-06-09 10:23:37 -0700404/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800405 * To be called from dispatch thread
406 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700407 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800408 */
409static void
Etan Cohend3652192014-06-20 08:28:44 -0700410issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800411 RequestInfo *pRI;
412 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700413 /* Hook for current context */
414 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
415 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
416 /* pendingRequestsHook refer to &s_pendingRequests */
417 RequestInfo** pendingRequestsHook = &s_pendingRequests;
418
419#if (SIM_COUNT == 2)
420 if (socket_id == RIL_SOCKET_2) {
421 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
422 pendingRequestsHook = &s_pendingRequests_socket2;
423 }
424#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800425
426 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
427
428 pRI->local = 1;
429 pRI->token = 0xffffffff; // token is not used in this context
430 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700431 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800432
Etan Cohend3652192014-06-20 08:28:44 -0700433 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800434 assert (ret == 0);
435
Etan Cohend3652192014-06-20 08:28:44 -0700436 pRI->p_next = *pendingRequestsHook;
437 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800438
Etan Cohend3652192014-06-20 08:28:44 -0700439 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800440 assert (ret == 0);
441
Wink Saville8eb2a122012-11-19 16:05:13 -0800442 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800443
Etan Cohend3652192014-06-20 08:28:44 -0700444 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800445}
446
447
448
449static int
Etan Cohend3652192014-06-20 08:28:44 -0700450processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451 Parcel p;
452 status_t status;
453 int32_t request;
454 int32_t token;
455 RequestInfo *pRI;
456 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700457 /* Hook for current context */
458 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
459 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
460 /* pendingRequestsHook refer to &s_pendingRequests */
461 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462
463 p.setData((uint8_t *) buffer, buflen);
464
465 // status checked at end
466 status = p.readInt32(&request);
467 status = p.readInt32 (&token);
468
Etan Cohend3652192014-06-20 08:28:44 -0700469 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
470
471#if (SIM_COUNT >= 2)
472 if (socket_id == RIL_SOCKET_2) {
473 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
474 pendingRequestsHook = &s_pendingRequests_socket2;
475 }
476#if (SIM_COUNT >= 3)
477 else if (socket_id == RIL_SOCKET_3) {
478 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
479 pendingRequestsHook = &s_pendingRequests_socket3;
480 }
481#endif
482#if (SIM_COUNT >= 4)
483 else if (socket_id == RIL_SOCKET_4) {
484 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
485 pendingRequestsHook = &s_pendingRequests_socket4;
486 }
487#endif
488#endif
489
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800490 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800491 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800492 return 0;
493 }
494
495 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700496 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800497 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800498 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700499 pErr.writeInt32 (RESPONSE_SOLICITED);
500 pErr.writeInt32 (token);
501 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
502
503 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800504 return 0;
505 }
506
507
508 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
509
510 pRI->token = token;
511 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700512 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800513
Etan Cohend3652192014-06-20 08:28:44 -0700514 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800515 assert (ret == 0);
516
Etan Cohend3652192014-06-20 08:28:44 -0700517 pRI->p_next = *pendingRequestsHook;
518 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800519
Etan Cohend3652192014-06-20 08:28:44 -0700520 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800521 assert (ret == 0);
522
523/* sLastDispatchedToken = token; */
524
Wink Saville7f856802009-06-09 10:23:37 -0700525 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800526
527 return 0;
528}
529
530static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700531invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800532 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800533 pRI->token, requestToString(pRI->pCI->requestNumber));
534}
535
536/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700537static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700538dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539 clearPrintBuf;
540 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700541 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800542}
543
544/** Callee expects const char * */
545static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700546dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547 status_t status;
548 size_t datalen;
549 size_t stringlen;
550 char *string8 = NULL;
551
552 string8 = strdupReadString(p);
553
554 startRequest;
555 appendPrintBuf("%s%s", printBuf, string8);
556 closeRequest;
557 printRequest(pRI->token, pRI->pCI->requestNumber);
558
Etan Cohend3652192014-06-20 08:28:44 -0700559 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
560 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800561
562#ifdef MEMSET_FREED
563 memsetString(string8);
564#endif
565
566 free(string8);
567 return;
568invalid:
569 invalidCommandBlock(pRI);
570 return;
571}
572
573/** Callee expects const char ** */
574static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700575dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800576 int32_t countStrings;
577 status_t status;
578 size_t datalen;
579 char **pStrings;
580
581 status = p.readInt32 (&countStrings);
582
583 if (status != NO_ERROR) {
584 goto invalid;
585 }
586
587 startRequest;
588 if (countStrings == 0) {
589 // just some non-null pointer
590 pStrings = (char **)alloca(sizeof(char *));
591 datalen = 0;
592 } else if (((int)countStrings) == -1) {
593 pStrings = NULL;
594 datalen = 0;
595 } else {
596 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700597
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800598 pStrings = (char **)alloca(datalen);
599
600 for (int i = 0 ; i < countStrings ; i++) {
601 pStrings[i] = strdupReadString(p);
602 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
603 }
604 }
605 removeLastChar;
606 closeRequest;
607 printRequest(pRI->token, pRI->pCI->requestNumber);
608
Etan Cohend3652192014-06-20 08:28:44 -0700609 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800610
611 if (pStrings != NULL) {
612 for (int i = 0 ; i < countStrings ; i++) {
613#ifdef MEMSET_FREED
614 memsetString (pStrings[i]);
615#endif
616 free(pStrings[i]);
617 }
618
619#ifdef MEMSET_FREED
620 memset(pStrings, 0, datalen);
621#endif
622 }
Wink Saville7f856802009-06-09 10:23:37 -0700623
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800624 return;
625invalid:
626 invalidCommandBlock(pRI);
627 return;
628}
629
630/** Callee expects const int * */
631static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700632dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800633 int32_t count;
634 status_t status;
635 size_t datalen;
636 int *pInts;
637
638 status = p.readInt32 (&count);
639
640 if (status != NO_ERROR || count == 0) {
641 goto invalid;
642 }
643
644 datalen = sizeof(int) * count;
645 pInts = (int *)alloca(datalen);
646
647 startRequest;
648 for (int i = 0 ; i < count ; i++) {
649 int32_t t;
650
651 status = p.readInt32(&t);
652 pInts[i] = (int)t;
653 appendPrintBuf("%s%d,", printBuf, t);
654
655 if (status != NO_ERROR) {
656 goto invalid;
657 }
658 }
659 removeLastChar;
660 closeRequest;
661 printRequest(pRI->token, pRI->pCI->requestNumber);
662
Etan Cohend3652192014-06-20 08:28:44 -0700663 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
664 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800665
666#ifdef MEMSET_FREED
667 memset(pInts, 0, datalen);
668#endif
669
670 return;
671invalid:
672 invalidCommandBlock(pRI);
673 return;
674}
675
676
Wink Saville7f856802009-06-09 10:23:37 -0700677/**
678 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800679 * Payload is:
680 * int32_t status
681 * String pdu
682 */
683static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700684dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800685 RIL_SMS_WriteArgs args;
686 int32_t t;
687 status_t status;
688
689 memset (&args, 0, sizeof(args));
690
691 status = p.readInt32(&t);
692 args.status = (int)t;
693
694 args.pdu = strdupReadString(p);
695
696 if (status != NO_ERROR || args.pdu == NULL) {
697 goto invalid;
698 }
699
700 args.smsc = strdupReadString(p);
701
702 startRequest;
703 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
704 (char*)args.pdu, (char*)args.smsc);
705 closeRequest;
706 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700707
Etan Cohend3652192014-06-20 08:28:44 -0700708 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800709
710#ifdef MEMSET_FREED
711 memsetString (args.pdu);
712#endif
713
714 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700715
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800716#ifdef MEMSET_FREED
717 memset(&args, 0, sizeof(args));
718#endif
719
720 return;
721invalid:
722 invalidCommandBlock(pRI);
723 return;
724}
725
Wink Saville7f856802009-06-09 10:23:37 -0700726/**
727 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800728 * Payload is:
729 * String address
730 * int32_t clir
731 */
732static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700733dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800734 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800735 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800736 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800737 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800738 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800739 status_t status;
740
741 memset (&dial, 0, sizeof(dial));
742
743 dial.address = strdupReadString(p);
744
745 status = p.readInt32(&t);
746 dial.clir = (int)t;
747
748 if (status != NO_ERROR || dial.address == NULL) {
749 goto invalid;
750 }
751
Wink Saville3a4840b2010-04-07 13:29:58 -0700752 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800753 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800754 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800755 } else {
756 status = p.readInt32(&uusPresent);
757
758 if (status != NO_ERROR) {
759 goto invalid;
760 }
761
762 if (uusPresent == 0) {
763 dial.uusInfo = NULL;
764 } else {
765 int32_t len;
766
767 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
768
769 status = p.readInt32(&t);
770 uusInfo.uusType = (RIL_UUS_Type) t;
771
772 status = p.readInt32(&t);
773 uusInfo.uusDcs = (RIL_UUS_DCS) t;
774
775 status = p.readInt32(&len);
776 if (status != NO_ERROR) {
777 goto invalid;
778 }
779
780 // The java code writes -1 for null arrays
781 if (((int) len) == -1) {
782 uusInfo.uusData = NULL;
783 len = 0;
784 } else {
785 uusInfo.uusData = (char*) p.readInplace(len);
786 }
787
788 uusInfo.uusLength = len;
789 dial.uusInfo = &uusInfo;
790 }
Wink Saville7bce0822010-01-08 15:20:12 -0800791 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800792 }
793
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800794 startRequest;
795 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800796 if (uusPresent) {
797 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
798 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
799 dial.uusInfo->uusLength);
800 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800801 closeRequest;
802 printRequest(pRI->token, pRI->pCI->requestNumber);
803
Etan Cohend3652192014-06-20 08:28:44 -0700804 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800805
806#ifdef MEMSET_FREED
807 memsetString (dial.address);
808#endif
809
810 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700811
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800812#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800813 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800814 memset(&dial, 0, sizeof(dial));
815#endif
816
817 return;
818invalid:
819 invalidCommandBlock(pRI);
820 return;
821}
822
Wink Saville7f856802009-06-09 10:23:37 -0700823/**
824 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800825 * Payload is:
826 * int32_t command
827 * int32_t fileid
828 * String path
829 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700830 * String data
831 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800832 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800833 */
834static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700835dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800836 union RIL_SIM_IO {
837 RIL_SIM_IO_v6 v6;
838 RIL_SIM_IO_v5 v5;
839 } simIO;
840
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800841 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800842 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800843 status_t status;
844
845 memset (&simIO, 0, sizeof(simIO));
846
Wink Saville7f856802009-06-09 10:23:37 -0700847 // note we only check status at the end
848
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800849 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800850 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800851
852 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800853 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800854
Wink Savillec0114b32011-02-18 10:14:07 -0800855 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800856
857 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800858 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859
860 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800861 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800862
863 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800864 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800865
Wink Savillec0114b32011-02-18 10:14:07 -0800866 simIO.v6.data = strdupReadString(p);
867 simIO.v6.pin2 = strdupReadString(p);
868 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869
870 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800871 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
872 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
873 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
874 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800875 closeRequest;
876 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700877
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878 if (status != NO_ERROR) {
879 goto invalid;
880 }
881
Wink Savillec0114b32011-02-18 10:14:07 -0800882 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700883 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884
885#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800886 memsetString (simIO.v6.path);
887 memsetString (simIO.v6.data);
888 memsetString (simIO.v6.pin2);
889 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800890#endif
891
Wink Savillec0114b32011-02-18 10:14:07 -0800892 free (simIO.v6.path);
893 free (simIO.v6.data);
894 free (simIO.v6.pin2);
895 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700896
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897#ifdef MEMSET_FREED
898 memset(&simIO, 0, sizeof(simIO));
899#endif
900
901 return;
902invalid:
903 invalidCommandBlock(pRI);
904 return;
905}
906
907/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800908 * Callee expects const RIL_SIM_APDU *
909 * Payload is:
910 * int32_t sessionid
911 * int32_t cla
912 * int32_t instruction
913 * int32_t p1, p2, p3
914 * String data
915 */
916static void
917dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
918 int32_t t;
919 status_t status;
920 RIL_SIM_APDU apdu;
921
922 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
923
924 // Note we only check status at the end. Any single failure leads to
925 // subsequent reads filing.
926 status = p.readInt32(&t);
927 apdu.sessionid = (int)t;
928
929 status = p.readInt32(&t);
930 apdu.cla = (int)t;
931
932 status = p.readInt32(&t);
933 apdu.instruction = (int)t;
934
935 status = p.readInt32(&t);
936 apdu.p1 = (int)t;
937
938 status = p.readInt32(&t);
939 apdu.p2 = (int)t;
940
941 status = p.readInt32(&t);
942 apdu.p3 = (int)t;
943
944 apdu.data = strdupReadString(p);
945
946 startRequest;
947 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
948 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
949 apdu.p3, (char*)apdu.data);
950 closeRequest;
951 printRequest(pRI->token, pRI->pCI->requestNumber);
952
953 if (status != NO_ERROR) {
954 goto invalid;
955 }
956
Etan Cohend3652192014-06-20 08:28:44 -0700957 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800958
959#ifdef MEMSET_FREED
960 memsetString(apdu.data);
961#endif
962 free(apdu.data);
963
964#ifdef MEMSET_FREED
965 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
966#endif
967
968 return;
969invalid:
970 invalidCommandBlock(pRI);
971 return;
972}
973
974
975/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800976 * Callee expects const RIL_CallForwardInfo *
977 * Payload is:
978 * int32_t status/action
979 * int32_t reason
980 * int32_t serviceCode
981 * int32_t toa
982 * String number (0 length -> null)
983 * int32_t timeSeconds
984 */
Wink Saville7f856802009-06-09 10:23:37 -0700985static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700986dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800987 RIL_CallForwardInfo cff;
988 int32_t t;
989 status_t status;
990
991 memset (&cff, 0, sizeof(cff));
992
Wink Saville7f856802009-06-09 10:23:37 -0700993 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800994
995 status = p.readInt32(&t);
996 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -0700997
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800998 status = p.readInt32(&t);
999 cff.reason = (int)t;
1000
1001 status = p.readInt32(&t);
1002 cff.serviceClass = (int)t;
1003
1004 status = p.readInt32(&t);
1005 cff.toa = (int)t;
1006
1007 cff.number = strdupReadString(p);
1008
1009 status = p.readInt32(&t);
1010 cff.timeSeconds = (int)t;
1011
1012 if (status != NO_ERROR) {
1013 goto invalid;
1014 }
1015
1016 // special case: number 0-length fields is null
1017
1018 if (cff.number != NULL && strlen (cff.number) == 0) {
1019 cff.number = NULL;
1020 }
1021
1022 startRequest;
1023 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1024 cff.status, cff.reason, cff.serviceClass, cff.toa,
1025 (char*)cff.number, cff.timeSeconds);
1026 closeRequest;
1027 printRequest(pRI->token, pRI->pCI->requestNumber);
1028
Etan Cohend3652192014-06-20 08:28:44 -07001029 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001030
1031#ifdef MEMSET_FREED
1032 memsetString(cff.number);
1033#endif
1034
1035 free (cff.number);
1036
1037#ifdef MEMSET_FREED
1038 memset(&cff, 0, sizeof(cff));
1039#endif
1040
1041 return;
1042invalid:
1043 invalidCommandBlock(pRI);
1044 return;
1045}
1046
1047
Wink Saville7f856802009-06-09 10:23:37 -07001048static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001049dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001050 int32_t len;
1051 status_t status;
1052 const void *data;
1053
1054 status = p.readInt32(&len);
1055
1056 if (status != NO_ERROR) {
1057 goto invalid;
1058 }
1059
1060 // The java code writes -1 for null arrays
1061 if (((int)len) == -1) {
1062 data = NULL;
1063 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001064 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001065
1066 data = p.readInplace(len);
1067
1068 startRequest;
1069 appendPrintBuf("%sraw_size=%d", printBuf, len);
1070 closeRequest;
1071 printRequest(pRI->token, pRI->pCI->requestNumber);
1072
Etan Cohend3652192014-06-20 08:28:44 -07001073 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001074
1075 return;
1076invalid:
1077 invalidCommandBlock(pRI);
1078 return;
1079}
1080
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001081static status_t
1082constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001083 int32_t t;
1084 uint8_t ut;
1085 status_t status;
1086 int32_t digitCount;
1087 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001088
Wink Savillef4c4d362009-04-02 01:37:03 -07001089 memset(&rcsm, 0, sizeof(rcsm));
1090
1091 status = p.readInt32(&t);
1092 rcsm.uTeleserviceID = (int) t;
1093
1094 status = p.read(&ut,sizeof(ut));
1095 rcsm.bIsServicePresent = (uint8_t) ut;
1096
1097 status = p.readInt32(&t);
1098 rcsm.uServicecategory = (int) t;
1099
1100 status = p.readInt32(&t);
1101 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1102
1103 status = p.readInt32(&t);
1104 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1105
1106 status = p.readInt32(&t);
1107 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1108
1109 status = p.readInt32(&t);
1110 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1111
1112 status = p.read(&ut,sizeof(ut));
1113 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1114
1115 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1116 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1117 status = p.read(&ut,sizeof(ut));
1118 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1119 }
1120
Wink Saville7f856802009-06-09 10:23:37 -07001121 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001122 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1123
Wink Saville7f856802009-06-09 10:23:37 -07001124 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001125 rcsm.sSubAddress.odd = (uint8_t) ut;
1126
1127 status = p.read(&ut,sizeof(ut));
1128 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1129
1130 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001131 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1132 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001133 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1134 }
1135
Wink Saville7f856802009-06-09 10:23:37 -07001136 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001137 rcsm.uBearerDataLen = (int) t;
1138
1139 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001140 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1141 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001142 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1143 }
1144
1145 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001146 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001147 }
1148
1149 startRequest;
1150 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001151 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001152 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001153 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001154 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001155
Wink Savillef4c4d362009-04-02 01:37:03 -07001156 printRequest(pRI->token, pRI->pCI->requestNumber);
1157
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001158 return status;
1159}
1160
1161static void
1162dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1163 RIL_CDMA_SMS_Message rcsm;
1164
1165 ALOGD("dispatchCdmaSms");
1166 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1167 goto invalid;
1168 }
1169
Etan Cohend3652192014-06-20 08:28:44 -07001170 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001171
1172#ifdef MEMSET_FREED
1173 memset(&rcsm, 0, sizeof(rcsm));
1174#endif
1175
1176 return;
1177
1178invalid:
1179 invalidCommandBlock(pRI);
1180 return;
1181}
1182
Wink Saville7f856802009-06-09 10:23:37 -07001183static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001184dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1185 RIL_IMS_SMS_Message rism;
1186 RIL_CDMA_SMS_Message rcsm;
1187
1188 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1189
1190 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1191 goto invalid;
1192 }
1193 memset(&rism, 0, sizeof(rism));
1194 rism.tech = RADIO_TECH_3GPP2;
1195 rism.retry = retry;
1196 rism.messageRef = messageRef;
1197 rism.message.cdmaMessage = &rcsm;
1198
Etan Cohend3652192014-06-20 08:28:44 -07001199 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001200 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001201 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001202
1203#ifdef MEMSET_FREED
1204 memset(&rcsm, 0, sizeof(rcsm));
1205 memset(&rism, 0, sizeof(rism));
1206#endif
1207
1208 return;
1209
1210invalid:
1211 invalidCommandBlock(pRI);
1212 return;
1213}
1214
1215static void
1216dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1217 RIL_IMS_SMS_Message rism;
1218 int32_t countStrings;
1219 status_t status;
1220 size_t datalen;
1221 char **pStrings;
1222 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1223
1224 status = p.readInt32 (&countStrings);
1225
1226 if (status != NO_ERROR) {
1227 goto invalid;
1228 }
1229
1230 memset(&rism, 0, sizeof(rism));
1231 rism.tech = RADIO_TECH_3GPP;
1232 rism.retry = retry;
1233 rism.messageRef = messageRef;
1234
1235 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001236 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1237 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001238 if (countStrings == 0) {
1239 // just some non-null pointer
1240 pStrings = (char **)alloca(sizeof(char *));
1241 datalen = 0;
1242 } else if (((int)countStrings) == -1) {
1243 pStrings = NULL;
1244 datalen = 0;
1245 } else {
1246 datalen = sizeof(char *) * countStrings;
1247
1248 pStrings = (char **)alloca(datalen);
1249
1250 for (int i = 0 ; i < countStrings ; i++) {
1251 pStrings[i] = strdupReadString(p);
1252 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1253 }
1254 }
1255 removeLastChar;
1256 closeRequest;
1257 printRequest(pRI->token, pRI->pCI->requestNumber);
1258
1259 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001260 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001261 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001262 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001263
1264 if (pStrings != NULL) {
1265 for (int i = 0 ; i < countStrings ; i++) {
1266#ifdef MEMSET_FREED
1267 memsetString (pStrings[i]);
1268#endif
1269 free(pStrings[i]);
1270 }
1271
1272#ifdef MEMSET_FREED
1273 memset(pStrings, 0, datalen);
1274#endif
1275 }
1276
1277#ifdef MEMSET_FREED
1278 memset(&rism, 0, sizeof(rism));
1279#endif
1280 return;
1281invalid:
1282 ALOGE("dispatchImsGsmSms invalid block");
1283 invalidCommandBlock(pRI);
1284 return;
1285}
1286
1287static void
1288dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1289 int32_t t;
1290 status_t status = p.readInt32(&t);
1291 RIL_RadioTechnologyFamily format;
1292 uint8_t retry;
1293 int32_t messageRef;
1294
1295 ALOGD("dispatchImsSms");
1296 if (status != NO_ERROR) {
1297 goto invalid;
1298 }
1299 format = (RIL_RadioTechnologyFamily) t;
1300
1301 // read retry field
1302 status = p.read(&retry,sizeof(retry));
1303 if (status != NO_ERROR) {
1304 goto invalid;
1305 }
1306 // read messageRef field
1307 status = p.read(&messageRef,sizeof(messageRef));
1308 if (status != NO_ERROR) {
1309 goto invalid;
1310 }
1311
1312 if (RADIO_TECH_3GPP == format) {
1313 dispatchImsGsmSms(p, pRI, retry, messageRef);
1314 } else if (RADIO_TECH_3GPP2 == format) {
1315 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1316 } else {
1317 ALOGE("requestImsSendSMS invalid format value =%d", format);
1318 }
1319
1320 return;
1321
1322invalid:
1323 invalidCommandBlock(pRI);
1324 return;
1325}
1326
1327static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001328dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1329 RIL_CDMA_SMS_Ack rcsa;
1330 int32_t t;
1331 status_t status;
1332 int32_t digitCount;
1333
1334 memset(&rcsa, 0, sizeof(rcsa));
1335
1336 status = p.readInt32(&t);
1337 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1338
1339 status = p.readInt32(&t);
1340 rcsa.uSMSCauseCode = (int) t;
1341
1342 if (status != NO_ERROR) {
1343 goto invalid;
1344 }
1345
1346 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001347 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1348 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001349 closeRequest;
1350
1351 printRequest(pRI->token, pRI->pCI->requestNumber);
1352
Etan Cohend3652192014-06-20 08:28:44 -07001353 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001354
1355#ifdef MEMSET_FREED
1356 memset(&rcsa, 0, sizeof(rcsa));
1357#endif
1358
1359 return;
1360
1361invalid:
1362 invalidCommandBlock(pRI);
1363 return;
1364}
1365
Wink Savillea592eeb2009-05-22 13:26:36 -07001366static void
1367dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1368 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001369 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001370 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001371
Wink Savillea592eeb2009-05-22 13:26:36 -07001372 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001373 if (status != NO_ERROR) {
1374 goto invalid;
1375 }
1376
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001377 {
1378 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1379 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001380
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001381 startRequest;
1382 for (int i = 0 ; i < num ; i++ ) {
1383 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001384
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001385 status = p.readInt32(&t);
1386 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001387
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001388 status = p.readInt32(&t);
1389 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001390
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001391 status = p.readInt32(&t);
1392 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001393
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001394 status = p.readInt32(&t);
1395 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001396
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001397 status = p.readInt32(&t);
1398 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001399
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001400 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1401 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1402 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1403 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1404 gsmBci[i].selected);
1405 }
1406 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001407
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001408 if (status != NO_ERROR) {
1409 goto invalid;
1410 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001411
Etan Cohend3652192014-06-20 08:28:44 -07001412 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001413 gsmBciPtrs,
1414 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001415 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001416
1417#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001418 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1419 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001420#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001421 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001422
1423 return;
1424
1425invalid:
1426 invalidCommandBlock(pRI);
1427 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001428}
Wink Savillef4c4d362009-04-02 01:37:03 -07001429
Wink Savillea592eeb2009-05-22 13:26:36 -07001430static void
1431dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1432 int32_t t;
1433 status_t status;
1434 int32_t num;
1435
1436 status = p.readInt32(&num);
1437 if (status != NO_ERROR) {
1438 goto invalid;
1439 }
1440
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001441 {
1442 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1443 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001444
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001445 startRequest;
1446 for (int i = 0 ; i < num ; i++ ) {
1447 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001448
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001449 status = p.readInt32(&t);
1450 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001451
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001452 status = p.readInt32(&t);
1453 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001454
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001455 status = p.readInt32(&t);
1456 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001457
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001458 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1459 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1460 cdmaBci[i].language, cdmaBci[i].selected);
1461 }
1462 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001463
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001464 if (status != NO_ERROR) {
1465 goto invalid;
1466 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001467
Etan Cohend3652192014-06-20 08:28:44 -07001468 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001469 cdmaBciPtrs,
1470 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001471 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001472
1473#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1475 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001476#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001477 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001478
1479 return;
1480
1481invalid:
1482 invalidCommandBlock(pRI);
1483 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001484}
1485
1486static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1487 RIL_CDMA_SMS_WriteArgs rcsw;
1488 int32_t t;
1489 uint32_t ut;
1490 uint8_t uct;
1491 status_t status;
1492 int32_t digitCount;
1493
1494 memset(&rcsw, 0, sizeof(rcsw));
1495
1496 status = p.readInt32(&t);
1497 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
Wink Savillef4c4d362009-04-02 01:37:03 -07001499 status = p.readInt32(&t);
1500 rcsw.message.uTeleserviceID = (int) t;
1501
1502 status = p.read(&uct,sizeof(uct));
1503 rcsw.message.bIsServicePresent = (uint8_t) uct;
1504
1505 status = p.readInt32(&t);
1506 rcsw.message.uServicecategory = (int) t;
1507
1508 status = p.readInt32(&t);
1509 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1510
1511 status = p.readInt32(&t);
1512 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1513
1514 status = p.readInt32(&t);
1515 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1516
1517 status = p.readInt32(&t);
1518 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1519
1520 status = p.read(&uct,sizeof(uct));
1521 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1522
1523 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1524 status = p.read(&uct,sizeof(uct));
1525 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1526 }
1527
Wink Savillea592eeb2009-05-22 13:26:36 -07001528 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001529 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1530
Wink Savillea592eeb2009-05-22 13:26:36 -07001531 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001532 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1533
1534 status = p.read(&uct,sizeof(uct));
1535 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1536
1537 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001538 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001539 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1540 }
1541
Wink Savillea592eeb2009-05-22 13:26:36 -07001542 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001543 rcsw.message.uBearerDataLen = (int) t;
1544
1545 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001546 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001547 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1548 }
1549
1550 if (status != NO_ERROR) {
1551 goto invalid;
1552 }
1553
1554 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001555 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1556 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1557 message.sAddress.number_mode=%d, \
1558 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001559 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001560 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1561 rcsw.message.sAddress.number_mode,
1562 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001563 closeRequest;
1564
1565 printRequest(pRI->token, pRI->pCI->requestNumber);
1566
Etan Cohend3652192014-06-20 08:28:44 -07001567 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001568
1569#ifdef MEMSET_FREED
1570 memset(&rcsw, 0, sizeof(rcsw));
1571#endif
1572
1573 return;
1574
1575invalid:
1576 invalidCommandBlock(pRI);
1577 return;
1578
1579}
1580
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001581// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1582// Version 4 of the RIL interface adds a new PDP type parameter to support
1583// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1584// RIL, remove the parameter from the request.
1585static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1586 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1587 const int numParamsRilV3 = 6;
1588
1589 // The first bytes of the RIL parcel contain the request number and the
1590 // serial number - see processCommandBuffer(). Copy them over too.
1591 int pos = p.dataPosition();
1592
1593 int numParams = p.readInt32();
1594 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1595 Parcel p2;
1596 p2.appendFrom(&p, 0, pos);
1597 p2.writeInt32(numParamsRilV3);
1598 for(int i = 0; i < numParamsRilV3; i++) {
1599 p2.writeString16(p.readString16());
1600 }
1601 p2.setDataPosition(pos);
1602 dispatchStrings(p2, pRI);
1603 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001604 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001605 dispatchStrings(p, pRI);
1606 }
1607}
1608
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001609// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1610// When all RILs handle this request, this function can be removed and
1611// the request can be sent directly to the RIL using dispatchVoid.
1612static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001613 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001614
1615 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1616 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1617 }
1618
1619 // RILs that support RADIO_STATE_ON should support this request.
1620 if (RADIO_STATE_ON == state) {
1621 dispatchVoid(p, pRI);
1622 return;
1623 }
1624
1625 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1626 // will not support this new request either and decode Voice Radio Technology
1627 // from Radio State
1628 voiceRadioTech = decodeVoiceRadioTechnology(state);
1629
1630 if (voiceRadioTech < 0)
1631 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1632 else
1633 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1634}
1635
1636// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1637// When all RILs handle this request, this function can be removed and
1638// the request can be sent directly to the RIL using dispatchVoid.
1639static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001640 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001641
1642 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1643 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1644 }
1645
1646 // RILs that support RADIO_STATE_ON should support this request.
1647 if (RADIO_STATE_ON == state) {
1648 dispatchVoid(p, pRI);
1649 return;
1650 }
1651
1652 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1653 // will not support this new request either and decode CDMA Subscription Source
1654 // from Radio State
1655 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1656
1657 if (cdmaSubscriptionSource < 0)
1658 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1659 else
1660 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1661}
1662
Sungmin Choi75697532013-04-26 15:04:45 -07001663static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1664{
1665 RIL_InitialAttachApn pf;
1666 int32_t t;
1667 status_t status;
1668
1669 memset(&pf, 0, sizeof(pf));
1670
1671 pf.apn = strdupReadString(p);
1672 pf.protocol = strdupReadString(p);
1673
1674 status = p.readInt32(&t);
1675 pf.authtype = (int) t;
1676
1677 pf.username = strdupReadString(p);
1678 pf.password = strdupReadString(p);
1679
1680 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001681 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1682 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001683 closeRequest;
1684 printRequest(pRI->token, pRI->pCI->requestNumber);
1685
1686 if (status != NO_ERROR) {
1687 goto invalid;
1688 }
Etan Cohend3652192014-06-20 08:28:44 -07001689 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001690
1691#ifdef MEMSET_FREED
1692 memsetString(pf.apn);
1693 memsetString(pf.protocol);
1694 memsetString(pf.username);
1695 memsetString(pf.password);
1696#endif
1697
1698 free(pf.apn);
1699 free(pf.protocol);
1700 free(pf.username);
1701 free(pf.password);
1702
1703#ifdef MEMSET_FREED
1704 memset(&pf, 0, sizeof(pf));
1705#endif
1706
1707 return;
1708invalid:
1709 invalidCommandBlock(pRI);
1710 return;
1711}
1712
Jake Hamby8a4a2332014-01-15 13:12:05 -08001713static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1714 RIL_NV_ReadItem nvri;
1715 int32_t t;
1716 status_t status;
1717
1718 memset(&nvri, 0, sizeof(nvri));
1719
1720 status = p.readInt32(&t);
1721 nvri.itemID = (RIL_NV_Item) t;
1722
1723 if (status != NO_ERROR) {
1724 goto invalid;
1725 }
1726
1727 startRequest;
1728 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1729 closeRequest;
1730
1731 printRequest(pRI->token, pRI->pCI->requestNumber);
1732
Etan Cohend3652192014-06-20 08:28:44 -07001733 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001734
1735#ifdef MEMSET_FREED
1736 memset(&nvri, 0, sizeof(nvri));
1737#endif
1738
1739 return;
1740
1741invalid:
1742 invalidCommandBlock(pRI);
1743 return;
1744}
1745
1746static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1747 RIL_NV_WriteItem nvwi;
1748 int32_t t;
1749 status_t status;
1750
1751 memset(&nvwi, 0, sizeof(nvwi));
1752
1753 status = p.readInt32(&t);
1754 nvwi.itemID = (RIL_NV_Item) t;
1755
1756 nvwi.value = strdupReadString(p);
1757
1758 if (status != NO_ERROR || nvwi.value == NULL) {
1759 goto invalid;
1760 }
1761
1762 startRequest;
1763 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1764 nvwi.value);
1765 closeRequest;
1766
1767 printRequest(pRI->token, pRI->pCI->requestNumber);
1768
Etan Cohend3652192014-06-20 08:28:44 -07001769 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001770
1771#ifdef MEMSET_FREED
1772 memsetString(nvwi.value);
1773#endif
1774
1775 free(nvwi.value);
1776
1777#ifdef MEMSET_FREED
1778 memset(&nvwi, 0, sizeof(nvwi));
1779#endif
1780
1781 return;
1782
1783invalid:
1784 invalidCommandBlock(pRI);
1785 return;
1786}
1787
1788
Etan Cohend3652192014-06-20 08:28:44 -07001789static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1790 RIL_SelectUiccSub uicc_sub;
1791 status_t status;
1792 int32_t t;
1793 memset(&uicc_sub, 0, sizeof(uicc_sub));
1794
1795 status = p.readInt32(&t);
1796 if (status != NO_ERROR) {
1797 goto invalid;
1798 }
1799 uicc_sub.slot = (int) t;
1800
1801 status = p.readInt32(&t);
1802 if (status != NO_ERROR) {
1803 goto invalid;
1804 }
1805 uicc_sub.app_index = (int) t;
1806
1807 status = p.readInt32(&t);
1808 if (status != NO_ERROR) {
1809 goto invalid;
1810 }
1811 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1812
1813 status = p.readInt32(&t);
1814 if (status != NO_ERROR) {
1815 goto invalid;
1816 }
1817 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1818
1819 startRequest;
1820 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1821 uicc_sub.act_status);
1822 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1823 uicc_sub.app_index, uicc_sub.act_status);
1824 closeRequest;
1825 printRequest(pRI->token, pRI->pCI->requestNumber);
1826
1827 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1828
1829#ifdef MEMSET_FREED
1830 memset(&uicc_sub, 0, sizeof(uicc_sub));
1831#endif
1832 return;
1833
1834invalid:
1835 invalidCommandBlock(pRI);
1836 return;
1837}
1838
Amit Mahajan90530a62014-07-01 15:54:08 -07001839static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1840{
1841 RIL_SimAuthentication pf;
1842 int32_t t;
1843 status_t status;
1844
1845 memset(&pf, 0, sizeof(pf));
1846
1847 status = p.readInt32(&t);
1848 pf.authContext = (int) t;
1849 pf.authData = strdupReadString(p);
1850 pf.aid = strdupReadString(p);
1851
1852 startRequest;
1853 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1854 closeRequest;
1855 printRequest(pRI->token, pRI->pCI->requestNumber);
1856
1857 if (status != NO_ERROR) {
1858 goto invalid;
1859 }
1860 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1861
1862#ifdef MEMSET_FREED
1863 memsetString(pf.authData);
1864 memsetString(pf.aid);
1865#endif
1866
1867 free(pf.authData);
1868 free(pf.aid);
1869
1870#ifdef MEMSET_FREED
1871 memset(&pf, 0, sizeof(pf));
1872#endif
1873
1874 return;
1875invalid:
1876 invalidCommandBlock(pRI);
1877 return;
1878}
1879
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001880static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001881blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07001882 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001883 const uint8_t *toWrite;
1884
1885 toWrite = (const uint8_t *)buffer;
1886
1887 while (writeOffset < len) {
1888 ssize_t written;
1889 do {
1890 written = write (fd, toWrite + writeOffset,
1891 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05301892 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001893
1894 if (written >= 0) {
1895 writeOffset += written;
1896 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08001897 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001898 close(fd);
1899 return -1;
1900 }
1901 }
1902
1903 return 0;
1904}
1905
1906static int
Etan Cohend3652192014-06-20 08:28:44 -07001907sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1908 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001909 int ret;
1910 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07001911 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001912
Etan Cohend3652192014-06-20 08:28:44 -07001913 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1914
1915#if (SIM_COUNT >= 2)
1916 if (socket_id == RIL_SOCKET_2) {
1917 fd = s_ril_param_socket2.fdCommand;
1918 writeMutexHook = &s_writeMutex_socket2;
1919 }
1920#if (SIM_COUNT >= 3)
1921 else if (socket_id == RIL_SOCKET_3) {
1922 fd = s_ril_param_socket3.fdCommand;
1923 writeMutexHook = &s_writeMutex_socket3;
1924 }
1925#endif
1926#if (SIM_COUNT >= 4)
1927 else if (socket_id == RIL_SOCKET_4) {
1928 fd = s_ril_param_socket4.fdCommand;
1929 writeMutexHook = &s_writeMutex_socket4;
1930 }
1931#endif
1932#endif
1933 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001934 return -1;
1935 }
1936
1937 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001938 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001939 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1940
1941 return -1;
1942 }
Wink Saville7f856802009-06-09 10:23:37 -07001943
Etan Cohend3652192014-06-20 08:28:44 -07001944 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001945
1946 header = htonl(dataSize);
1947
1948 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1949
1950 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07001951 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001952 return ret;
1953 }
1954
Kennyee1fadc2009-08-13 00:45:53 +08001955 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001956
1957 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07001958 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001959 return ret;
1960 }
1961
Etan Cohend3652192014-06-20 08:28:44 -07001962 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001963
1964 return 0;
1965}
1966
1967static int
Etan Cohend3652192014-06-20 08:28:44 -07001968sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001969 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07001970 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001971}
1972
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07001973/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07001974
1975static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001976responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001977 int numInts;
1978
1979 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001980 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001981 return RIL_ERRNO_INVALID_RESPONSE;
1982 }
1983 if (responselen % sizeof(int) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001984 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001985 (int)responselen, (int)sizeof(int));
1986 return RIL_ERRNO_INVALID_RESPONSE;
1987 }
1988
1989 int *p_int = (int *) response;
1990
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07001991 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001992 p.writeInt32 (numInts);
1993
1994 /* each int*/
1995 startResponse;
1996 for (int i = 0 ; i < numInts ; i++) {
1997 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1998 p.writeInt32(p_int[i]);
1999 }
2000 removeLastChar;
2001 closeResponse;
2002
2003 return 0;
2004}
2005
Wink Saville43808972011-01-13 17:39:51 -08002006/** response is a char **, pointing to an array of char *'s
2007 The parcel will begin with the version */
2008static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2009 p.writeInt32(version);
2010 return responseStrings(p, response, responselen);
2011}
2012
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002013/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002014static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002015 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002016
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002017 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002018 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002019 return RIL_ERRNO_INVALID_RESPONSE;
2020 }
2021 if (responselen % sizeof(char *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002022 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002023 (int)responselen, (int)sizeof(char *));
2024 return RIL_ERRNO_INVALID_RESPONSE;
2025 }
2026
2027 if (response == NULL) {
2028 p.writeInt32 (0);
2029 } else {
2030 char **p_cur = (char **) response;
2031
2032 numStrings = responselen / sizeof(char *);
2033 p.writeInt32 (numStrings);
2034
2035 /* each string*/
2036 startResponse;
2037 for (int i = 0 ; i < numStrings ; i++) {
2038 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2039 writeStringToParcel (p, p_cur[i]);
2040 }
2041 removeLastChar;
2042 closeResponse;
2043 }
2044 return 0;
2045}
2046
2047
2048/**
Wink Saville7f856802009-06-09 10:23:37 -07002049 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002050 * FIXME currently ignores responselen
2051 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002052static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002053 /* one string only */
2054 startResponse;
2055 appendPrintBuf("%s%s", printBuf, (char*)response);
2056 closeResponse;
2057
2058 writeStringToParcel(p, (const char *)response);
2059
2060 return 0;
2061}
2062
Wink Savillef4c4d362009-04-02 01:37:03 -07002063static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002064 startResponse;
2065 removeLastChar;
2066 return 0;
2067}
2068
Wink Savillef4c4d362009-04-02 01:37:03 -07002069static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002070 int num;
2071
2072 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002073 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002074 return RIL_ERRNO_INVALID_RESPONSE;
2075 }
2076
2077 if (responselen % sizeof (RIL_Call *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002078 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002079 (int)responselen, (int)sizeof (RIL_Call *));
2080 return RIL_ERRNO_INVALID_RESPONSE;
2081 }
2082
2083 startResponse;
2084 /* number of call info's */
2085 num = responselen / sizeof(RIL_Call *);
2086 p.writeInt32(num);
2087
2088 for (int i = 0 ; i < num ; i++) {
2089 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2090 /* each call info */
2091 p.writeInt32(p_cur->state);
2092 p.writeInt32(p_cur->index);
2093 p.writeInt32(p_cur->toa);
2094 p.writeInt32(p_cur->isMpty);
2095 p.writeInt32(p_cur->isMT);
2096 p.writeInt32(p_cur->als);
2097 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002098 p.writeInt32(p_cur->isVoicePrivacy);
2099 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002100 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002101 writeStringToParcel(p, p_cur->name);
2102 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002103 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002104 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2105 p.writeInt32(0); /* UUS Information is absent */
2106 } else {
2107 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2108 p.writeInt32(1); /* UUS Information is present */
2109 p.writeInt32(uusInfo->uusType);
2110 p.writeInt32(uusInfo->uusDcs);
2111 p.writeInt32(uusInfo->uusLength);
2112 p.write(uusInfo->uusData, uusInfo->uusLength);
2113 }
Wink Saville3d54e742009-05-18 18:00:44 -07002114 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002115 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002116 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002117 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002118 p_cur->toa);
2119 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2120 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002121 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002122 (p_cur->isMT)?"mt":"mo",
2123 p_cur->als,
2124 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002125 (p_cur->isVoicePrivacy)?"evp":"noevp");
2126 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2127 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002128 p_cur->number,
2129 p_cur->numberPresentation,
2130 p_cur->name,
2131 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132 }
2133 removeLastChar;
2134 closeResponse;
2135
2136 return 0;
2137}
2138
Wink Savillef4c4d362009-04-02 01:37:03 -07002139static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002140 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002141 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002142 return RIL_ERRNO_INVALID_RESPONSE;
2143 }
2144
2145 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002146 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002147 (int)responselen, (int)sizeof (RIL_SMS_Response));
2148 return RIL_ERRNO_INVALID_RESPONSE;
2149 }
2150
2151 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2152
2153 p.writeInt32(p_cur->messageRef);
2154 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002155 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002156
2157 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002158 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2159 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002160 closeResponse;
2161
2162 return 0;
2163}
2164
Wink Savillec0114b32011-02-18 10:14:07 -08002165static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002166{
2167 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002168 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002169 return RIL_ERRNO_INVALID_RESPONSE;
2170 }
2171
Wink Savillec0114b32011-02-18 10:14:07 -08002172 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002173 RLOGE("invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002174 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002175 return RIL_ERRNO_INVALID_RESPONSE;
2176 }
2177
Wink Savillec0114b32011-02-18 10:14:07 -08002178 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002179 p.writeInt32(num);
2180
Wink Savillec0114b32011-02-18 10:14:07 -08002181 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002182 startResponse;
2183 int i;
2184 for (i = 0; i < num; i++) {
2185 p.writeInt32(p_cur[i].cid);
2186 p.writeInt32(p_cur[i].active);
2187 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002188 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002189 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002190 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002191 p_cur[i].cid,
2192 (p_cur[i].active==0)?"down":"up",
2193 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002194 (char*)p_cur[i].address);
2195 }
2196 removeLastChar;
2197 closeResponse;
2198
2199 return 0;
2200}
2201
Etan Cohend3652192014-06-20 08:28:44 -07002202static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2203{
2204 if (response == NULL && responselen != 0) {
2205 RLOGE("invalid response: NULL");
2206 return RIL_ERRNO_INVALID_RESPONSE;
2207 }
2208
2209 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2210 RLOGE("invalid response length %d expected multiple of %d",
2211 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2212 return RIL_ERRNO_INVALID_RESPONSE;
2213 }
2214
2215 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2216 p.writeInt32(num);
2217
2218 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2219 startResponse;
2220 int i;
2221 for (i = 0; i < num; i++) {
2222 p.writeInt32((int)p_cur[i].status);
2223 p.writeInt32(p_cur[i].suggestedRetryTime);
2224 p.writeInt32(p_cur[i].cid);
2225 p.writeInt32(p_cur[i].active);
2226 writeStringToParcel(p, p_cur[i].type);
2227 writeStringToParcel(p, p_cur[i].ifname);
2228 writeStringToParcel(p, p_cur[i].addresses);
2229 writeStringToParcel(p, p_cur[i].dnses);
2230 writeStringToParcel(p, p_cur[i].gateways);
2231 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2232 p_cur[i].status,
2233 p_cur[i].suggestedRetryTime,
2234 p_cur[i].cid,
2235 (p_cur[i].active==0)?"down":"up",
2236 (char*)p_cur[i].type,
2237 (char*)p_cur[i].ifname,
2238 (char*)p_cur[i].addresses,
2239 (char*)p_cur[i].dnses,
2240 (char*)p_cur[i].gateways);
2241 }
2242 removeLastChar;
2243 closeResponse;
2244
2245 return 0;
2246}
2247
Wink Saville43808972011-01-13 17:39:51 -08002248static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2249{
2250 // Write version
2251 p.writeInt32(s_callbacks.version);
2252
2253 if (s_callbacks.version < 5) {
Wink Savillec0114b32011-02-18 10:14:07 -08002254 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002255 } else {
2256 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002257 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002258 return RIL_ERRNO_INVALID_RESPONSE;
2259 }
2260
Etan Cohend3652192014-06-20 08:28:44 -07002261 // Support v6 or v9 with new rils
2262 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2263 return responseDataCallListV6(p, response, responselen);
2264 }
2265
2266 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002267 RLOGE("invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002268 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002269 return RIL_ERRNO_INVALID_RESPONSE;
2270 }
2271
Etan Cohend3652192014-06-20 08:28:44 -07002272 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002273 p.writeInt32(num);
2274
Etan Cohend3652192014-06-20 08:28:44 -07002275 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002276 startResponse;
2277 int i;
2278 for (i = 0; i < num; i++) {
2279 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002280 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002281 p.writeInt32(p_cur[i].cid);
2282 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002283 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002284 writeStringToParcel(p, p_cur[i].ifname);
2285 writeStringToParcel(p, p_cur[i].addresses);
2286 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002287 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002288 writeStringToParcel(p, p_cur[i].pcscf);
2289 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002290 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002291 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002292 p_cur[i].cid,
2293 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002294 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002295 (char*)p_cur[i].ifname,
2296 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002297 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002298 (char*)p_cur[i].gateways,
2299 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002300 }
2301 removeLastChar;
2302 closeResponse;
2303 }
2304
2305 return 0;
2306}
2307
2308static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2309{
2310 if (s_callbacks.version < 5) {
2311 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2312 } else {
2313 return responseDataCallList(p, response, responselen);
2314 }
2315}
2316
Wink Savillef4c4d362009-04-02 01:37:03 -07002317static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002318 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002319 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002320 return RIL_ERRNO_INVALID_RESPONSE;
2321 }
2322
2323 // The java code reads -1 size as null byte array
2324 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002325 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002326 } else {
2327 p.writeInt32(responselen);
2328 p.write(response, responselen);
2329 }
2330
2331 return 0;
2332}
2333
2334
Wink Savillef4c4d362009-04-02 01:37:03 -07002335static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002336 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002337 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002338 return RIL_ERRNO_INVALID_RESPONSE;
2339 }
2340
2341 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002342 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002343 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2344 return RIL_ERRNO_INVALID_RESPONSE;
2345 }
2346
2347 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2348 p.writeInt32(p_cur->sw1);
2349 p.writeInt32(p_cur->sw2);
2350 writeStringToParcel(p, p_cur->simResponse);
2351
2352 startResponse;
2353 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2354 (char*)p_cur->simResponse);
2355 closeResponse;
2356
2357
2358 return 0;
2359}
2360
Wink Savillef4c4d362009-04-02 01:37:03 -07002361static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002362 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002363
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002364 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002365 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002366 return RIL_ERRNO_INVALID_RESPONSE;
2367 }
2368
2369 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002370 RLOGE("invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002371 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2372 return RIL_ERRNO_INVALID_RESPONSE;
2373 }
2374
2375 /* number of call info's */
2376 num = responselen / sizeof(RIL_CallForwardInfo *);
2377 p.writeInt32(num);
2378
2379 startResponse;
2380 for (int i = 0 ; i < num ; i++) {
2381 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2382
2383 p.writeInt32(p_cur->status);
2384 p.writeInt32(p_cur->reason);
2385 p.writeInt32(p_cur->serviceClass);
2386 p.writeInt32(p_cur->toa);
2387 writeStringToParcel(p, p_cur->number);
2388 p.writeInt32(p_cur->timeSeconds);
2389 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2390 (p_cur->status==1)?"enable":"disable",
2391 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2392 (char*)p_cur->number,
2393 p_cur->timeSeconds);
2394 }
2395 removeLastChar;
2396 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002397
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002398 return 0;
2399}
2400
Wink Savillef4c4d362009-04-02 01:37:03 -07002401static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002402 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002403 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002404 return RIL_ERRNO_INVALID_RESPONSE;
2405 }
2406
2407 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002408 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002409 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2410 return RIL_ERRNO_INVALID_RESPONSE;
2411 }
2412
2413 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2414 p.writeInt32(p_cur->notificationType);
2415 p.writeInt32(p_cur->code);
2416 p.writeInt32(p_cur->index);
2417 p.writeInt32(p_cur->type);
2418 writeStringToParcel(p, p_cur->number);
2419
2420 startResponse;
2421 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2422 (p_cur->notificationType==0)?"mo":"mt",
2423 p_cur->code, p_cur->index, p_cur->type,
2424 (char*)p_cur->number);
2425 closeResponse;
2426
2427 return 0;
2428}
2429
Wink Saville3d54e742009-05-18 18:00:44 -07002430static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002431 int num;
2432
2433 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002434 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002435 return RIL_ERRNO_INVALID_RESPONSE;
2436 }
2437
2438 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002439 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002440 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2441 return RIL_ERRNO_INVALID_RESPONSE;
2442 }
2443
2444 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002445 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002446 num = responselen / sizeof(RIL_NeighboringCell *);
2447 p.writeInt32(num);
2448
2449 for (int i = 0 ; i < num ; i++) {
2450 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2451
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002452 p.writeInt32(p_cur->rssi);
2453 writeStringToParcel (p, p_cur->cid);
2454
2455 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2456 p_cur->cid, p_cur->rssi);
2457 }
2458 removeLastChar;
2459 closeResponse;
2460
2461 return 0;
2462}
2463
Wink Saville3d54e742009-05-18 18:00:44 -07002464/**
2465 * Marshall the signalInfoRecord into the parcel if it exists.
2466 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002467static void marshallSignalInfoRecord(Parcel &p,
2468 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002469 p.writeInt32(p_signalInfoRecord.isPresent);
2470 p.writeInt32(p_signalInfoRecord.signalType);
2471 p.writeInt32(p_signalInfoRecord.alertPitch);
2472 p.writeInt32(p_signalInfoRecord.signal);
2473}
2474
Wink Savillea592eeb2009-05-22 13:26:36 -07002475static int responseCdmaInformationRecords(Parcel &p,
2476 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002477 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002478 char* string8 = NULL;
2479 int buffer_lenght;
2480 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002481
2482 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002483 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002484 return RIL_ERRNO_INVALID_RESPONSE;
2485 }
2486
Wink Savillea592eeb2009-05-22 13:26:36 -07002487 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002488 RLOGE("invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002489 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002490 return RIL_ERRNO_INVALID_RESPONSE;
2491 }
2492
Wink Savillea592eeb2009-05-22 13:26:36 -07002493 RIL_CDMA_InformationRecords *p_cur =
2494 (RIL_CDMA_InformationRecords *) response;
2495 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002496
2497 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002498 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002499
Wink Savillea592eeb2009-05-22 13:26:36 -07002500 for (int i = 0 ; i < num ; i++) {
2501 infoRec = &p_cur->infoRec[i];
2502 p.writeInt32(infoRec->name);
2503 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002504 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002505 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2506 if (infoRec->rec.display.alpha_len >
2507 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002508 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002509 expected not more than %d\n",
2510 (int)infoRec->rec.display.alpha_len,
2511 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2512 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002513 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002514 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2515 * sizeof(char) );
2516 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2517 string8[i] = infoRec->rec.display.alpha_buf[i];
2518 }
Wink Saville43808972011-01-13 17:39:51 -08002519 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002520 writeStringToParcel(p, (const char*)string8);
2521 free(string8);
2522 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002523 break;
2524 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002525 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002526 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002527 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002528 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002529 expected not more than %d\n",
2530 (int)infoRec->rec.number.len,
2531 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2532 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002533 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002534 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2535 * sizeof(char) );
2536 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2537 string8[i] = infoRec->rec.number.buf[i];
2538 }
Wink Saville43808972011-01-13 17:39:51 -08002539 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002540 writeStringToParcel(p, (const char*)string8);
2541 free(string8);
2542 string8 = NULL;
2543 p.writeInt32(infoRec->rec.number.number_type);
2544 p.writeInt32(infoRec->rec.number.number_plan);
2545 p.writeInt32(infoRec->rec.number.pi);
2546 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002547 break;
2548 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002549 p.writeInt32(infoRec->rec.signal.isPresent);
2550 p.writeInt32(infoRec->rec.signal.signalType);
2551 p.writeInt32(infoRec->rec.signal.alertPitch);
2552 p.writeInt32(infoRec->rec.signal.signal);
2553
2554 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2555 alertPitch=%X, signal=%X, ",
2556 printBuf, (int)infoRec->rec.signal.isPresent,
2557 (int)infoRec->rec.signal.signalType,
2558 (int)infoRec->rec.signal.alertPitch,
2559 (int)infoRec->rec.signal.signal);
2560 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002561 break;
2562 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002563 if (infoRec->rec.redir.redirectingNumber.len >
2564 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002565 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002566 expected not more than %d\n",
2567 (int)infoRec->rec.redir.redirectingNumber.len,
2568 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2569 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002570 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002571 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2572 .len + 1) * sizeof(char) );
2573 for (int i = 0;
2574 i < infoRec->rec.redir.redirectingNumber.len;
2575 i++) {
2576 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2577 }
Wink Saville43808972011-01-13 17:39:51 -08002578 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002579 writeStringToParcel(p, (const char*)string8);
2580 free(string8);
2581 string8 = NULL;
2582 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2583 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2584 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2585 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2586 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002587 break;
2588 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002589 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2590 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2591 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2592 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2593
2594 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2595 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2596 lineCtrlPowerDenial=%d, ", printBuf,
2597 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2598 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2599 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2600 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2601 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002602 break;
2603 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002604 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002605
Wink Savillea592eeb2009-05-22 13:26:36 -07002606 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2607 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002608 break;
2609 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002610 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2611 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2612
2613 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2614 infoRec->rec.audioCtrl.upLink,
2615 infoRec->rec.audioCtrl.downLink);
2616 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002617 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002618 case RIL_CDMA_T53_RELEASE_INFO_REC:
2619 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002620 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002621 return RIL_ERRNO_INVALID_RESPONSE;
2622 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002623 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002624 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002625 }
2626 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002627 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002628
Wink Savillea592eeb2009-05-22 13:26:36 -07002629 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002630}
2631
Wink Savillea592eeb2009-05-22 13:26:36 -07002632static int responseRilSignalStrength(Parcel &p,
2633 void *response, size_t responselen) {
2634 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002635 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002636 return RIL_ERRNO_INVALID_RESPONSE;
2637 }
2638
Wink Savillec0114b32011-02-18 10:14:07 -08002639 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002640 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002641
Wink Saville3d54e742009-05-18 18:00:44 -07002642 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2643 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2644 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2645 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2646 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2647 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2648 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002649 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002650 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002651 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002652 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002653 if (s_callbacks.version <= 6) {
2654 // signalStrength: -1 -> 99
2655 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2656 p_cur->LTE_SignalStrength.signalStrength = 99;
2657 }
2658 // rsrp: -1 -> INT_MAX all other negative value to positive.
2659 // So remap here
2660 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2661 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2662 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2663 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2664 }
2665 // rsrq: -1 -> INT_MAX
2666 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2667 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2668 }
2669 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002670
Wink Saville18e4ab12013-04-07 17:31:04 -07002671 // cqi: -1 -> INT_MAX
2672 if (p_cur->LTE_SignalStrength.cqi == -1) {
2673 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2674 }
2675 }
2676 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002677 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2678 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2679 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2680 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002681 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2682 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2683 } else {
2684 p.writeInt32(INT_MAX);
2685 }
Wink Savillec0114b32011-02-18 10:14:07 -08002686 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002687 p.writeInt32(99);
2688 p.writeInt32(INT_MAX);
2689 p.writeInt32(INT_MAX);
2690 p.writeInt32(INT_MAX);
2691 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002692 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002693 }
johnwangfdf825f2009-05-22 15:50:34 -07002694
2695 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002696 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002697 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2698 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2699 EVDO_SS.signalNoiseRatio=%d,\
2700 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002701 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002702 printBuf,
2703 p_cur->GW_SignalStrength.signalStrength,
2704 p_cur->GW_SignalStrength.bitErrorRate,
2705 p_cur->CDMA_SignalStrength.dbm,
2706 p_cur->CDMA_SignalStrength.ecio,
2707 p_cur->EVDO_SignalStrength.dbm,
2708 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002709 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2710 p_cur->LTE_SignalStrength.signalStrength,
2711 p_cur->LTE_SignalStrength.rsrp,
2712 p_cur->LTE_SignalStrength.rsrq,
2713 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002714 p_cur->LTE_SignalStrength.cqi,
2715 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002716 closeResponse;
2717
Wink Saville3d54e742009-05-18 18:00:44 -07002718 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002719 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002720 return RIL_ERRNO_INVALID_RESPONSE;
2721 }
2722
Wink Saville3d54e742009-05-18 18:00:44 -07002723 return 0;
2724}
2725
2726static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2727 if ((response == NULL) || (responselen == 0)) {
2728 return responseVoid(p, response, responselen);
2729 } else {
2730 return responseCdmaSignalInfoRecord(p, response, responselen);
2731 }
2732}
2733
2734static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2735 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002736 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002737 return RIL_ERRNO_INVALID_RESPONSE;
2738 }
2739
2740 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002741 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002742 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2743 return RIL_ERRNO_INVALID_RESPONSE;
2744 }
2745
2746 startResponse;
2747
2748 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2749 marshallSignalInfoRecord(p, *p_cur);
2750
2751 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2752 signal=%d]",
2753 printBuf,
2754 p_cur->isPresent,
2755 p_cur->signalType,
2756 p_cur->alertPitch,
2757 p_cur->signal);
2758
2759 closeResponse;
2760 return 0;
2761}
2762
Wink Savillea592eeb2009-05-22 13:26:36 -07002763static int responseCdmaCallWaiting(Parcel &p, void *response,
2764 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002765 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002766 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002767 return RIL_ERRNO_INVALID_RESPONSE;
2768 }
2769
Wink Savillec0114b32011-02-18 10:14:07 -08002770 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002771 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002772 }
2773
2774 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2775
2776 writeStringToParcel(p, p_cur->number);
2777 p.writeInt32(p_cur->numberPresentation);
2778 writeStringToParcel(p, p_cur->name);
2779 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2780
2781 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2782 p.writeInt32(p_cur->number_type);
2783 p.writeInt32(p_cur->number_plan);
2784 } else {
2785 p.writeInt32(0);
2786 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002787 }
2788
2789 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002790 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2791 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002792 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002793 printBuf,
2794 p_cur->number,
2795 p_cur->numberPresentation,
2796 p_cur->name,
2797 p_cur->signalInfoRecord.isPresent,
2798 p_cur->signalInfoRecord.signalType,
2799 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002800 p_cur->signalInfoRecord.signal,
2801 p_cur->number_type,
2802 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002803 closeResponse;
2804
2805 return 0;
2806}
2807
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002808static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2809 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002810 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002811 return RIL_ERRNO_INVALID_RESPONSE;
2812 }
2813
2814 startResponse;
2815 if (s_callbacks.version == 7) {
2816 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2817 p.writeInt32(p_cur->result);
2818 p.writeInt32(p_cur->ef_id);
2819 writeStringToParcel(p, p_cur->aid);
2820
2821 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2822 printBuf,
2823 p_cur->result,
2824 p_cur->ef_id,
2825 p_cur->aid);
2826 } else {
2827 int *p_cur = ((int *) response);
2828 p.writeInt32(p_cur[0]);
2829 p.writeInt32(p_cur[1]);
2830 writeStringToParcel(p, NULL);
2831
2832 appendPrintBuf("%sresult=%d, ef_id=%d",
2833 printBuf,
2834 p_cur[0],
2835 p_cur[1]);
2836 }
2837 closeResponse;
2838
2839 return 0;
2840}
2841
Wink Saville8a9e0212013-04-09 12:11:38 -07002842static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2843{
2844 if (response == NULL && responselen != 0) {
2845 RLOGE("invalid response: NULL");
2846 return RIL_ERRNO_INVALID_RESPONSE;
2847 }
2848
2849 if (responselen % sizeof(RIL_CellInfo) != 0) {
2850 RLOGE("invalid response length %d expected multiple of %d",
2851 (int)responselen, (int)sizeof(RIL_CellInfo));
2852 return RIL_ERRNO_INVALID_RESPONSE;
2853 }
2854
2855 int num = responselen / sizeof(RIL_CellInfo);
2856 p.writeInt32(num);
2857
2858 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2859 startResponse;
2860 int i;
2861 for (i = 0; i < num; i++) {
2862 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2863 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2864 p.writeInt32((int)p_cur->cellInfoType);
2865 p.writeInt32(p_cur->registered);
2866 p.writeInt32(p_cur->timeStampType);
2867 p.writeInt64(p_cur->timeStamp);
2868 switch(p_cur->cellInfoType) {
2869 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07002870 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002871 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2872 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2873 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07002874 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2875 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002876 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2877 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2878
2879 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2880 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2881 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2882 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07002883 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2884 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2885 break;
2886 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07002887 case RIL_CELL_INFO_TYPE_WCDMA: {
2888 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2889 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2890 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2891 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2892 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2893 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2894 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2895 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2896 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2897
2898 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2899 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2900 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2901 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2902 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2903 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2904 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2905 break;
2906 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002907 case RIL_CELL_INFO_TYPE_CDMA: {
2908 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2909 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2910 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2911 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2912 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2913 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2914
2915 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2916 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2917 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2918 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2919 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2920
2921 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2922 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2923 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2924 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2925 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2926 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2927
2928 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2929 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2930 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2931 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2932 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2933 break;
2934 }
2935 case RIL_CELL_INFO_TYPE_LTE: {
2936 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2937 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2938 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2939 p_cur->CellInfo.lte.cellIdentityLte.ci,
2940 p_cur->CellInfo.lte.cellIdentityLte.pci,
2941 p_cur->CellInfo.lte.cellIdentityLte.tac);
2942
2943 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2944 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2945 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2946 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2947 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2948
2949 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2950 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2951 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2952 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2953 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2954 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2955 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2956 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2957 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2958 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2959 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2960 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2961 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2962 break;
2963 }
Etan Cohend3652192014-06-20 08:28:44 -07002964 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
2965 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
2966 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
2967 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
2968 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
2969 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
2970 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
2971 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
2972 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
2973
2974 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
2975 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
2976 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
2977 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
2978 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
2979 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
2980 break;
2981 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002982 }
2983 p_cur += 1;
2984 }
2985 removeLastChar;
2986 closeResponse;
2987
2988 return 0;
2989}
2990
Etan Cohend3652192014-06-20 08:28:44 -07002991static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
2992{
2993 if (response == NULL && responselen != 0) {
2994 RLOGE("invalid response: NULL");
2995 return RIL_ERRNO_INVALID_RESPONSE;
2996 }
2997
2998 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
2999 RLOGE("invalid response length %d expected multiple of %d",
3000 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3001 return RIL_ERRNO_INVALID_RESPONSE;
3002 }
3003
3004 int num = responselen / sizeof(RIL_HardwareConfig);
3005 int i;
3006 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3007
3008 p.writeInt32(num);
3009
3010 startResponse;
3011 for (i = 0; i < num; i++) {
3012 switch (p_cur[i].type) {
3013 case RIL_HARDWARE_CONFIG_MODEM: {
3014 writeStringToParcel(p, p_cur[i].uuid);
3015 p.writeInt32((int)p_cur[i].state);
3016 p.writeInt32(p_cur[i].cfg.modem.rat);
3017 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3018 p.writeInt32(p_cur[i].cfg.modem.maxData);
3019 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3020
3021 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3022 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3023 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3024 break;
3025 }
3026 case RIL_HARDWARE_CONFIG_SIM: {
3027 writeStringToParcel(p, p_cur[i].uuid);
3028 p.writeInt32((int)p_cur[i].state);
3029 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3030
3031 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3032 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3033 break;
3034 }
3035 }
3036 }
3037 removeLastChar;
3038 closeResponse;
3039 return 0;
3040}
3041
Wink Saville3d54e742009-05-18 18:00:44 -07003042static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003043 int ret;
3044 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3045 /* trigger event loop to wakeup. No reason to do this,
3046 * if we're in the event loop thread */
3047 do {
3048 ret = write (s_fdWakeupWrite, " ", 1);
3049 } while (ret < 0 && errno == EINTR);
3050 }
3051}
3052
Wink Saville3d54e742009-05-18 18:00:44 -07003053static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003054 ril_event_add(ev);
3055 triggerEvLoop();
3056}
3057
Wink Savillefd729372011-02-22 16:19:39 -08003058static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3059 p.writeInt32(num_apps);
3060 startResponse;
3061 for (int i = 0; i < num_apps; i++) {
3062 p.writeInt32(appStatus[i].app_type);
3063 p.writeInt32(appStatus[i].app_state);
3064 p.writeInt32(appStatus[i].perso_substate);
3065 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3066 writeStringToParcel(p, (const char*)
3067 (appStatus[i].app_label_ptr));
3068 p.writeInt32(appStatus[i].pin1_replaced);
3069 p.writeInt32(appStatus[i].pin1);
3070 p.writeInt32(appStatus[i].pin2);
3071 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3072 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3073 printBuf,
3074 appStatus[i].app_type,
3075 appStatus[i].app_state,
3076 appStatus[i].perso_substate,
3077 appStatus[i].aid_ptr,
3078 appStatus[i].app_label_ptr,
3079 appStatus[i].pin1_replaced,
3080 appStatus[i].pin1,
3081 appStatus[i].pin2);
3082 }
3083 closeResponse;
3084}
3085
Wink Savillef4c4d362009-04-02 01:37:03 -07003086static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3087 int i;
3088
3089 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003090 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003091 return RIL_ERRNO_INVALID_RESPONSE;
3092 }
3093
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003094 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003095 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003096
Wink Savillefd729372011-02-22 16:19:39 -08003097 p.writeInt32(p_cur->card_state);
3098 p.writeInt32(p_cur->universal_pin_state);
3099 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3100 p.writeInt32(p_cur->cdma_subscription_app_index);
3101 p.writeInt32(p_cur->ims_subscription_app_index);
3102
3103 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003104 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003105 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3106
3107 p.writeInt32(p_cur->card_state);
3108 p.writeInt32(p_cur->universal_pin_state);
3109 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3110 p.writeInt32(p_cur->cdma_subscription_app_index);
3111 p.writeInt32(-1);
3112
3113 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003114 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003115 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003116 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003117 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003118
3119 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003120}
Wink Savillef4c4d362009-04-02 01:37:03 -07003121
Wink Savillea592eeb2009-05-22 13:26:36 -07003122static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3123 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003124 p.writeInt32(num);
3125
Wink Savillef4c4d362009-04-02 01:37:03 -07003126 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003127 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3128 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3129 for (int i = 0; i < num; i++) {
3130 p.writeInt32(p_cur[i]->fromServiceId);
3131 p.writeInt32(p_cur[i]->toServiceId);
3132 p.writeInt32(p_cur[i]->fromCodeScheme);
3133 p.writeInt32(p_cur[i]->toCodeScheme);
3134 p.writeInt32(p_cur[i]->selected);
3135
3136 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3137 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3138 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3139 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3140 p_cur[i]->selected);
3141 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003142 closeResponse;
3143
3144 return 0;
3145}
3146
Wink Savillea592eeb2009-05-22 13:26:36 -07003147static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3148 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3149 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003150
Wink Savillea592eeb2009-05-22 13:26:36 -07003151 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3152 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003153
3154 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003155 for (int i = 0 ; i < num ; i++ ) {
3156 p.writeInt32(p_cur[i]->service_category);
3157 p.writeInt32(p_cur[i]->language);
3158 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003159
Wink Savillea592eeb2009-05-22 13:26:36 -07003160 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3161 selected =%d], ",
3162 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3163 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003164 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003165 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003166
Wink Savillef4c4d362009-04-02 01:37:03 -07003167 return 0;
3168}
3169
3170static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3171 int num;
3172 int digitCount;
3173 int digitLimit;
3174 uint8_t uct;
3175 void* dest;
3176
Wink Saville8eb2a122012-11-19 16:05:13 -08003177 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003178
Wink Savillef4c4d362009-04-02 01:37:03 -07003179 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003180 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003181 return RIL_ERRNO_INVALID_RESPONSE;
3182 }
3183
Wink Savillef5903df2009-04-24 11:54:14 -07003184 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003185 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003186 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003187 return RIL_ERRNO_INVALID_RESPONSE;
3188 }
3189
3190 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3191 p.writeInt32(p_cur->uTeleserviceID);
3192 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3193 p.writeInt32(p_cur->uServicecategory);
3194 p.writeInt32(p_cur->sAddress.digit_mode);
3195 p.writeInt32(p_cur->sAddress.number_mode);
3196 p.writeInt32(p_cur->sAddress.number_type);
3197 p.writeInt32(p_cur->sAddress.number_plan);
3198 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3199 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3200 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3201 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3202 }
3203
3204 p.writeInt32(p_cur->sSubAddress.subaddressType);
3205 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3206 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3207 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3208 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3209 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3210 }
3211
3212 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3213 p.writeInt32(p_cur->uBearerDataLen);
3214 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3215 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3216 }
3217
3218 startResponse;
3219 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003220 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003221 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3222 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3223 closeResponse;
3224
3225 return 0;
3226}
3227
Wink Savillec29360a2014-07-13 05:17:28 -07003228static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3229{
3230 int num = responselen / sizeof(RIL_DcRtInfo);
3231 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3232 RLOGE("invalid response length %d expected multiple of %d",
3233 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3234 return RIL_ERRNO_INVALID_RESPONSE;
3235 }
3236
3237 startResponse;
3238 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3239 p.writeInt64(pDcRtInfo->time);
3240 p.writeInt32(pDcRtInfo->powerState);
3241 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3242 pDcRtInfo->time,
3243 pDcRtInfo->powerState);
3244 closeResponse;
3245
3246 return 0;
3247}
3248
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003249/**
3250 * A write on the wakeup fd is done just to pop us out of select()
3251 * We empty the buffer here and then ril_event will reset the timers on the
3252 * way back down
3253 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003254static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003255 char buff[16];
3256 int ret;
3257
Wink Saville8eb2a122012-11-19 16:05:13 -08003258 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003259
3260 /* empty our wakeup socket out */
3261 do {
3262 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003263 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003264}
3265
Etan Cohend3652192014-06-20 08:28:44 -07003266static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003267 int ret;
3268 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003269 /* Hook for current context
3270 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3271 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3272 /* pendingRequestsHook refer to &s_pendingRequests */
3273 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003274
Etan Cohend3652192014-06-20 08:28:44 -07003275#if (SIM_COUNT >= 2)
3276 if (socket_id == RIL_SOCKET_2) {
3277 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3278 pendingRequestsHook = &s_pendingRequests_socket2;
3279 }
3280#if (SIM_COUNT >= 3)
3281 else if (socket_id == RIL_SOCKET_3) {
3282 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3283 pendingRequestsHook = &s_pendingRequests_socket3;
3284 }
3285#endif
3286#if (SIM_COUNT >= 4)
3287 else if (socket_id == RIL_SOCKET_4) {
3288 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3289 pendingRequestsHook = &s_pendingRequests_socket4;
3290 }
3291#endif
3292#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003293 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003294 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003295 assert (ret == 0);
3296
Etan Cohend3652192014-06-20 08:28:44 -07003297 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003298
Etan Cohend3652192014-06-20 08:28:44 -07003299 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003300 ; p_cur != NULL
3301 ; p_cur = p_cur->p_next
3302 ) {
3303 p_cur->cancelled = 1;
3304 }
3305
Etan Cohend3652192014-06-20 08:28:44 -07003306 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003307 assert (ret == 0);
3308}
3309
Wink Savillef4c4d362009-04-02 01:37:03 -07003310static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003311 RecordStream *p_rs;
3312 void *p_record;
3313 size_t recordlen;
3314 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003315 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003316
Etan Cohend3652192014-06-20 08:28:44 -07003317 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003318
Etan Cohend3652192014-06-20 08:28:44 -07003319 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003320
3321 for (;;) {
3322 /* loop until EAGAIN/EINTR, end of stream, or other error */
3323 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3324
3325 if (ret == 0 && p_record == NULL) {
3326 /* end-of-stream */
3327 break;
3328 } else if (ret < 0) {
3329 break;
3330 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003331 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003332 }
3333 }
3334
3335 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3336 /* fatal error or end-of-stream */
3337 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003338 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003339 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003340 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003341 }
Wink Saville7f856802009-06-09 10:23:37 -07003342
Etan Cohend3652192014-06-20 08:28:44 -07003343 close(fd);
3344 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003345
Etan Cohend3652192014-06-20 08:28:44 -07003346 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003347
3348 record_stream_free(p_rs);
3349
3350 /* start listening for new connections again */
3351 rilEventAddWakeup(&s_listen_event);
3352
Etan Cohend3652192014-06-20 08:28:44 -07003353 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003354 }
3355}
3356
3357
Etan Cohend3652192014-06-20 08:28:44 -07003358static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003359 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003360 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003361 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3362 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003363
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003364 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003365 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3366 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003367
3368 // Send last NITZ time data, in case it was missed
3369 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003370 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003371
3372 free(s_lastNITZTimeData);
3373 s_lastNITZTimeData = NULL;
3374 }
3375
3376 // Get version string
3377 if (s_callbacks.getVersion != NULL) {
3378 const char *version;
3379 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003380 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003381
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003382 property_set(PROPERTY_RIL_IMPL, version);
3383 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003384 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003385 property_set(PROPERTY_RIL_IMPL, "unavailable");
3386 }
3387
3388}
3389
Wink Savillef4c4d362009-04-02 01:37:03 -07003390static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003391 int ret;
3392 int err;
3393 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003394 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003395 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003396 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003397
3398 struct sockaddr_un peeraddr;
3399 socklen_t socklen = sizeof (peeraddr);
3400
3401 struct ucred creds;
3402 socklen_t szCreds = sizeof(creds);
3403
3404 struct passwd *pwd = NULL;
3405
Etan Cohend3652192014-06-20 08:28:44 -07003406 assert (*p_info->fdCommand < 0);
3407 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003408
Etan Cohend3652192014-06-20 08:28:44 -07003409 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003410
Etan Cohend3652192014-06-20 08:28:44 -07003411 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003412 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003413 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003414 rilEventAddWakeup(p_info->listen_event);
3415 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003416 }
3417
3418 /* check the credential of the other side and only accept socket from
3419 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003420 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003421 errno = 0;
3422 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003423
Etan Cohend3652192014-06-20 08:28:44 -07003424 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003425
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003426 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003427 errno = 0;
3428 pwd = getpwuid(creds.uid);
3429 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003430 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003431 is_phone_socket = 1;
3432 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003433 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003434 }
3435 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003436 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003437 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003438 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003439 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003440 }
3441
Etan Cohend3652192014-06-20 08:28:44 -07003442 if (!is_phone_socket) {
3443 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003444
Etan Cohend3652192014-06-20 08:28:44 -07003445 close(fdCommand);
3446 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003447
Etan Cohend3652192014-06-20 08:28:44 -07003448 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003449
3450 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003451 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003452
3453 return;
3454 }
3455
Etan Cohend3652192014-06-20 08:28:44 -07003456 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003457
3458 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003459 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003460 }
3461
Etan Cohend3652192014-06-20 08:28:44 -07003462 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003463
Etan Cohend3652192014-06-20 08:28:44 -07003464 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003465
Etan Cohend3652192014-06-20 08:28:44 -07003466 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003467
Etan Cohend3652192014-06-20 08:28:44 -07003468 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003469
Etan Cohend3652192014-06-20 08:28:44 -07003470 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3471 p_info->processCommandsCallback, p_info);
3472
3473 rilEventAddWakeup (p_info->commands_event);
3474
3475 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003476}
3477
3478static void freeDebugCallbackArgs(int number, char **args) {
3479 for (int i = 0; i < number; i++) {
3480 if (args[i] != NULL) {
3481 free(args[i]);
3482 }
3483 }
3484 free(args);
3485}
3486
Wink Savillef4c4d362009-04-02 01:37:03 -07003487static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003488 int acceptFD, option;
3489 struct sockaddr_un peeraddr;
3490 socklen_t socklen = sizeof (peeraddr);
3491 int data;
3492 unsigned int qxdm_data[6];
3493 const char *deactData[1] = {"1"};
3494 char *actData[1];
3495 RIL_Dial dialData;
3496 int hangupData[1] = {1};
3497 int number;
3498 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003499 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3500 int sim_id = 0;
3501
3502 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003503
3504 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3505
3506 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003507 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003508 return;
3509 }
3510
3511 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003512 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003513 return;
3514 }
3515 args = (char **) malloc(sizeof(char*) * number);
3516
3517 for (int i = 0; i < number; i++) {
3518 int len;
3519 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003520 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003521 freeDebugCallbackArgs(i, args);
3522 return;
3523 }
3524 // +1 for null-term
3525 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003526 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003527 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003528 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003529 freeDebugCallbackArgs(i, args);
3530 return;
3531 }
3532 char * buf = args[i];
3533 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003534 if ((i+1) == number) {
3535 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3536 sim_id = atoi(args[i]);
3537 switch (sim_id) {
3538 case 0:
3539 socket_id = RIL_SOCKET_1;
3540 break;
3541 #if (SIM_COUNT >= 2)
3542 case 1:
3543 socket_id = RIL_SOCKET_2;
3544 break;
3545 #endif
3546 #if (SIM_COUNT >= 3)
3547 case 2:
3548 socket_id = RIL_SOCKET_3;
3549 break;
3550 #endif
3551 #if (SIM_COUNT >= 4)
3552 case 3:
3553 socket_id = RIL_SOCKET_4;
3554 break;
3555 #endif
3556 default:
3557 socket_id = RIL_SOCKET_1;
3558 break;
3559 }
3560 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003561 }
3562
3563 switch (atoi(args[0])) {
3564 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003565 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003566 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003567 break;
3568 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003569 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003570 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003571 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003572 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003573 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3574 close(s_ril_param_socket.fdCommand);
3575 s_ril_param_socket.fdCommand = -1;
3576 }
3577 #if (SIM_COUNT == 2)
3578 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3579 close(s_ril_param_socket2.fdCommand);
3580 s_ril_param_socket2.fdCommand = -1;
3581 }
3582 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003583 break;
3584 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003585 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003586 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003587 break;
3588 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003589 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003590 qxdm_data[0] = 65536; // head.func_tag
3591 qxdm_data[1] = 16; // head.len
3592 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3593 qxdm_data[3] = 32; // log_file_size: 32megabytes
3594 qxdm_data[4] = 0; // log_mask
3595 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003596 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003597 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003598 break;
3599 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003600 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003601 qxdm_data[0] = 65536;
3602 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003603 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003604 qxdm_data[3] = 32;
3605 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003606 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003607 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003608 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003609 break;
3610 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003611 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003612 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003613 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003614 sleep(2);
3615 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003616 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003617 break;
3618 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003619 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003620 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003621 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003622 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003623 break;
3624 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003625 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003626 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003627 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003628 break;
3629 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003630 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003631 dialData.clir = 0;
3632 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003633 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003634 break;
3635 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003636 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003637 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003638 break;
3639 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003640 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003641 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003642 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003643 break;
3644 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003645 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003646 break;
3647 }
3648 freeDebugCallbackArgs(number, args);
3649 close(acceptFD);
3650}
3651
3652
Wink Savillef4c4d362009-04-02 01:37:03 -07003653static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003654 UserCallbackInfo *p_info;
3655
3656 p_info = (UserCallbackInfo *)param;
3657
3658 p_info->p_callback(p_info->userParam);
3659
3660
3661 // FIXME generalize this...there should be a cancel mechanism
3662 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3663 s_last_wake_timeout_info = NULL;
3664 }
3665
3666 free(p_info);
3667}
3668
3669
3670static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003671eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672 int ret;
3673 int filedes[2];
3674
3675 ril_event_init();
3676
3677 pthread_mutex_lock(&s_startupMutex);
3678
3679 s_started = 1;
3680 pthread_cond_broadcast(&s_startupCond);
3681
3682 pthread_mutex_unlock(&s_startupMutex);
3683
3684 ret = pipe(filedes);
3685
3686 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003687 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003688 return NULL;
3689 }
3690
3691 s_fdWakeupRead = filedes[0];
3692 s_fdWakeupWrite = filedes[1];
3693
3694 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3695
3696 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3697 processWakeupCallback, NULL);
3698
3699 rilEventAddWakeup (&s_wakeupfd_event);
3700
3701 // Only returns on error
3702 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003703 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003704 // kill self to restart on error
3705 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003706
3707 return NULL;
3708}
3709
Wink Saville7f856802009-06-09 10:23:37 -07003710extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003711RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003712 /* spin up eventLoop thread and wait for it to get started */
3713 s_started = 0;
3714 pthread_mutex_lock(&s_startupMutex);
3715
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003716 pthread_attr_t attr;
3717 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003718 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003719
Elliott Hughesfd81e712014-01-06 12:46:02 -08003720 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3721 if (result != 0) {
3722 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003723 goto done;
3724 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003725
3726 while (s_started == 0) {
3727 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3728 }
3729
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003730done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003731 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003732}
3733
3734// Used for testing purpose only.
3735extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3736 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3737}
3738
Etan Cohend3652192014-06-20 08:28:44 -07003739static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3740 int fdListen = -1;
3741 int ret;
3742 char socket_name[10];
3743
3744 memset(socket_name, 0, sizeof(char)*10);
3745
3746 switch(socket_id) {
3747 case RIL_SOCKET_1:
3748 strncpy(socket_name, RIL_getRilSocketName(), 9);
3749 break;
3750 #if (SIM_COUNT >= 2)
3751 case RIL_SOCKET_2:
3752 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3753 break;
3754 #endif
3755 #if (SIM_COUNT >= 3)
3756 case RIL_SOCKET_3:
3757 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3758 break;
3759 #endif
3760 #if (SIM_COUNT >= 4)
3761 case RIL_SOCKET_4:
3762 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3763 break;
3764 #endif
3765 default:
3766 RLOGE("Socket id is wrong!!");
3767 return;
3768 }
3769
3770 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3771
3772 fdListen = android_get_control_socket(socket_name);
3773 if (fdListen < 0) {
3774 RLOGE("Failed to get socket %s", socket_name);
3775 exit(-1);
3776 }
3777
3778 ret = listen(fdListen, 4);
3779
3780 if (ret < 0) {
3781 RLOGE("Failed to listen on control socket '%d': %s",
3782 fdListen, strerror(errno));
3783 exit(-1);
3784 }
3785 socket_listen_p->fdListen = fdListen;
3786
3787 /* note: non-persistent so we can accept only one connection at a time */
3788 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3789 listenCallback, socket_listen_p);
3790
3791 rilEventAddWakeup (socket_listen_p->listen_event);
3792}
3793
Wink Saville7f856802009-06-09 10:23:37 -07003794extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003795RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003796 int ret;
3797 int flags;
3798
Etan Cohend3652192014-06-20 08:28:44 -07003799 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3800
Wink Saville43808972011-01-13 17:39:51 -08003801 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003802 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003803 return;
3804 }
Wink Saville43808972011-01-13 17:39:51 -08003805 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003806 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003807 callbacks->version, RIL_VERSION_MIN);
3808 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07003809 }
Wink Saville43808972011-01-13 17:39:51 -08003810 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003811 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003812 callbacks->version, RIL_VERSION);
3813 return;
3814 }
Wink Saville8eb2a122012-11-19 16:05:13 -08003815 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003816
3817 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003818 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 "Subsequent call ignored");
3820 return;
3821 }
3822
3823 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3824
Etan Cohend3652192014-06-20 08:28:44 -07003825 /* Initialize socket1 parameters */
3826 s_ril_param_socket = {
3827 RIL_SOCKET_1, /* socket_id */
3828 -1, /* fdListen */
3829 -1, /* fdCommand */
3830 PHONE_PROCESS, /* processName */
3831 &s_commands_event, /* commands_event */
3832 &s_listen_event, /* listen_event */
3833 processCommandsCallback, /* processCommandsCallback */
3834 NULL /* p_rs */
3835 };
3836
3837#if (SIM_COUNT >= 2)
3838 s_ril_param_socket2 = {
3839 RIL_SOCKET_2, /* socket_id */
3840 -1, /* fdListen */
3841 -1, /* fdCommand */
3842 PHONE_PROCESS, /* processName */
3843 &s_commands_event_socket2, /* commands_event */
3844 &s_listen_event_socket2, /* listen_event */
3845 processCommandsCallback, /* processCommandsCallback */
3846 NULL /* p_rs */
3847 };
3848#endif
3849
3850#if (SIM_COUNT >= 3)
3851 s_ril_param_socket3 = {
3852 RIL_SOCKET_3, /* socket_id */
3853 -1, /* fdListen */
3854 -1, /* fdCommand */
3855 PHONE_PROCESS, /* processName */
3856 &s_commands_event_socket3, /* commands_event */
3857 &s_listen_event_socket3, /* listen_event */
3858 processCommandsCallback, /* processCommandsCallback */
3859 NULL /* p_rs */
3860 };
3861#endif
3862
3863#if (SIM_COUNT >= 4)
3864 s_ril_param_socket4 = {
3865 RIL_SOCKET_4, /* socket_id */
3866 -1, /* fdListen */
3867 -1, /* fdCommand */
3868 PHONE_PROCESS, /* processName */
3869 &s_commands_event_socket4, /* commands_event */
3870 &s_listen_event_socket4, /* listen_event */
3871 processCommandsCallback, /* processCommandsCallback */
3872 NULL /* p_rs */
3873 };
3874#endif
3875
3876
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003877 s_registerCalled = 1;
3878
Etan Cohend3652192014-06-20 08:28:44 -07003879 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003880 // Little self-check
3881
Wink Savillef4c4d362009-04-02 01:37:03 -07003882 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003883 assert(i == s_commands[i].requestNumber);
3884 }
3885
Wink Savillef4c4d362009-04-02 01:37:03 -07003886 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07003887 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003888 == s_unsolResponses[i].requestNumber);
3889 }
3890
3891 // New rild impl calls RIL_startEventLoop() first
3892 // old standalone impl wants it here.
3893
3894 if (s_started == 0) {
3895 RIL_startEventLoop();
3896 }
3897
Etan Cohend3652192014-06-20 08:28:44 -07003898 // start listen socket1
3899 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003900
Etan Cohend3652192014-06-20 08:28:44 -07003901#if (SIM_COUNT >= 2)
3902 // start listen socket2
3903 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
3904#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003905
Etan Cohend3652192014-06-20 08:28:44 -07003906#if (SIM_COUNT >= 3)
3907 // start listen socket3
3908 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
3909#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003910
Etan Cohend3652192014-06-20 08:28:44 -07003911#if (SIM_COUNT >= 4)
3912 // start listen socket4
3913 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
3914#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003915
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003916
3917#if 1
3918 // start debug interface socket
3919
Etan Cohend3652192014-06-20 08:28:44 -07003920 char *inst = NULL;
3921 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
3922 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
3923 }
3924
3925 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
3926 if (inst != NULL) {
3927 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
3928 }
3929
3930 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003931 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07003932 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003933 exit(-1);
3934 }
3935
3936 ret = listen(s_fdDebug, 4);
3937
3938 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003939 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003940 s_fdDebug, strerror(errno));
3941 exit(-1);
3942 }
3943
3944 ril_event_set (&s_debug_event, s_fdDebug, true,
3945 debugCallback, NULL);
3946
3947 rilEventAddWakeup (&s_debug_event);
3948#endif
3949
3950}
3951
3952static int
Wink Savillef4c4d362009-04-02 01:37:03 -07003953checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003954 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003955 /* Hook for current context
3956 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3957 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
3958 /* pendingRequestsHook refer to &s_pendingRequests */
3959 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07003960
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003961 if (pRI == NULL) {
3962 return 0;
3963 }
3964
Etan Cohend3652192014-06-20 08:28:44 -07003965#if (SIM_COUNT >= 2)
3966 if (pRI->socket_id == RIL_SOCKET_2) {
3967 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3968 pendingRequestsHook = &s_pendingRequests_socket2;
3969 }
3970#if (SIM_COUNT >= 3)
3971 if (pRI->socket_id == RIL_SOCKET_3) {
3972 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3973 pendingRequestsHook = &s_pendingRequests_socket3;
3974 }
3975#endif
3976#if (SIM_COUNT >= 4)
3977 if (pRI->socket_id == RIL_SOCKET_4) {
3978 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3979 pendingRequestsHook = &s_pendingRequests_socket4;
3980 }
3981#endif
3982#endif
3983 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003984
Etan Cohend3652192014-06-20 08:28:44 -07003985 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07003986 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003987 ; ppCur = &((*ppCur)->p_next)
3988 ) {
3989 if (pRI == *ppCur) {
3990 ret = 1;
3991
3992 *ppCur = (*ppCur)->p_next;
3993 break;
3994 }
3995 }
3996
Etan Cohend3652192014-06-20 08:28:44 -07003997 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003998
3999 return ret;
4000}
4001
4002
4003extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004004RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004005 RequestInfo *pRI;
4006 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004007 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004008 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004009 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004010
4011 pRI = (RequestInfo *)t;
4012
Etan Cohend3652192014-06-20 08:28:44 -07004013 socket_id = pRI->socket_id;
4014#if (SIM_COUNT >= 2)
4015 if (socket_id == RIL_SOCKET_2) {
4016 fd = s_ril_param_socket2.fdCommand;
4017 }
4018#if (SIM_COUNT >= 3)
4019 if (socket_id == RIL_SOCKET_3) {
4020 fd = s_ril_param_socket3.fdCommand;
4021 }
4022#endif
4023#if (SIM_COUNT >= 4)
4024 if (socket_id == RIL_SOCKET_4) {
4025 fd = s_ril_param_socket4.fdCommand;
4026 }
4027#endif
4028#endif
4029 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4030
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004031 if (!checkAndDequeueRequestInfo(pRI)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004032 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004033 return;
4034 }
4035
4036 if (pRI->local > 0) {
4037 // Locally issued command...void only!
4038 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004039 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004040
4041 goto done;
4042 }
4043
4044 appendPrintBuf("[%04d]< %s",
4045 pRI->token, requestToString(pRI->pCI->requestNumber));
4046
4047 if (pRI->cancelled == 0) {
4048 Parcel p;
4049
4050 p.writeInt32 (RESPONSE_SOLICITED);
4051 p.writeInt32 (pRI->token);
4052 errorOffset = p.dataPosition();
4053
4054 p.writeInt32 (e);
4055
johnwangb2a61842009-06-02 14:55:45 -07004056 if (response != NULL) {
4057 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004058 ret = pRI->pCI->responseFunction(p, response, responselen);
4059
4060 /* if an error occurred, rewind and mark it */
4061 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004062 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004063 p.setDataPosition(errorOffset);
4064 p.writeInt32 (ret);
4065 }
johnwangb2a61842009-06-02 14:55:45 -07004066 }
4067
4068 if (e != RIL_E_SUCCESS) {
4069 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004070 }
4071
Etan Cohend3652192014-06-20 08:28:44 -07004072 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004073 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004074 }
Etan Cohend3652192014-06-20 08:28:44 -07004075 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076 }
4077
4078done:
4079 free(pRI);
4080}
4081
4082
4083static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004084grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004085 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4086}
4087
4088static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004089releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004090 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4091}
4092
4093/**
4094 * Timer callback to put us back to sleep before the default timeout
4095 */
4096static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004097wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004098 // We're using "param != NULL" as a cancellation mechanism
4099 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004100 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004101
4102 releaseWakeLock();
4103 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004104 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004105 }
4106}
4107
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004108static int
4109decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4110 switch (radioState) {
4111 case RADIO_STATE_SIM_NOT_READY:
4112 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4113 case RADIO_STATE_SIM_READY:
4114 return RADIO_TECH_UMTS;
4115
4116 case RADIO_STATE_RUIM_NOT_READY:
4117 case RADIO_STATE_RUIM_READY:
4118 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4119 case RADIO_STATE_NV_NOT_READY:
4120 case RADIO_STATE_NV_READY:
4121 return RADIO_TECH_1xRTT;
4122
4123 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004124 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004125 return -1;
4126 }
4127}
4128
4129static int
4130decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4131 switch (radioState) {
4132 case RADIO_STATE_SIM_NOT_READY:
4133 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4134 case RADIO_STATE_SIM_READY:
4135 case RADIO_STATE_RUIM_NOT_READY:
4136 case RADIO_STATE_RUIM_READY:
4137 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4138 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4139
4140 case RADIO_STATE_NV_NOT_READY:
4141 case RADIO_STATE_NV_READY:
4142 return CDMA_SUBSCRIPTION_SOURCE_NV;
4143
4144 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004145 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004146 return -1;
4147 }
4148}
4149
4150static int
4151decodeSimStatus (RIL_RadioState radioState) {
4152 switch (radioState) {
4153 case RADIO_STATE_SIM_NOT_READY:
4154 case RADIO_STATE_RUIM_NOT_READY:
4155 case RADIO_STATE_NV_NOT_READY:
4156 case RADIO_STATE_NV_READY:
4157 return -1;
4158 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4159 case RADIO_STATE_SIM_READY:
4160 case RADIO_STATE_RUIM_READY:
4161 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4162 return radioState;
4163 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004164 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004165 return -1;
4166 }
4167}
4168
4169static bool is3gpp2(int radioTech) {
4170 switch (radioTech) {
4171 case RADIO_TECH_IS95A:
4172 case RADIO_TECH_IS95B:
4173 case RADIO_TECH_1xRTT:
4174 case RADIO_TECH_EVDO_0:
4175 case RADIO_TECH_EVDO_A:
4176 case RADIO_TECH_EVDO_B:
4177 case RADIO_TECH_EHRPD:
4178 return true;
4179 default:
4180 return false;
4181 }
4182}
4183
4184/* If RIL sends SIM states or RUIM states, store the voice radio
4185 * technology and subscription source information so that they can be
4186 * returned when telephony framework requests them
4187 */
4188static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004189processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004190
4191 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4192 int newVoiceRadioTech;
4193 int newCdmaSubscriptionSource;
4194 int newSimStatus;
4195
4196 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4197 from Radio State and send change notifications if there has been a change */
4198 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4199 if(newVoiceRadioTech != voiceRadioTech) {
4200 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004201 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4202 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004203 }
4204 if(is3gpp2(newVoiceRadioTech)) {
4205 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4206 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4207 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004208 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4209 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004210 }
4211 }
4212 newSimStatus = decodeSimStatus(newRadioState);
4213 if(newSimStatus != simRuimStatus) {
4214 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004215 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004216 }
4217
4218 /* Send RADIO_ON to telephony */
4219 newRadioState = RADIO_STATE_ON;
4220 }
4221
4222 return newRadioState;
4223}
4224
Etan Cohend3652192014-06-20 08:28:44 -07004225
4226#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004227extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004228void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4229 size_t datalen, RIL_SOCKET_ID socket_id)
4230#else
4231extern "C"
4232void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004233 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004234#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235{
4236 int unsolResponseIndex;
4237 int ret;
4238 int64_t timeReceived = 0;
4239 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004240 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004241 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4242
4243#if defined(ANDROID_MULTI_SIM)
4244 soc_id = socket_id;
4245#endif
4246
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004247
4248 if (s_registerCalled == 0) {
4249 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004250 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004251 return;
4252 }
Wink Saville7f856802009-06-09 10:23:37 -07004253
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004254 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4255
4256 if ((unsolResponseIndex < 0)
4257 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004258 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004259 return;
4260 }
4261
4262 // Grab a wake lock if needed for this reponse,
4263 // as we exit we'll either release it immediately
4264 // or set a timer to release it later.
4265 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4266 case WAKE_PARTIAL:
4267 grabPartialWakeLock();
4268 shouldScheduleTimeout = true;
4269 break;
4270
4271 case DONT_WAKE:
4272 default:
4273 // No wake lock is grabed so don't set timeout
4274 shouldScheduleTimeout = false;
4275 break;
4276 }
4277
4278 // Mark the time this was received, doing this
4279 // after grabing the wakelock incase getting
4280 // the elapsedRealTime might cause us to goto
4281 // sleep.
4282 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4283 timeReceived = elapsedRealtime();
4284 }
4285
4286 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4287
4288 Parcel p;
4289
4290 p.writeInt32 (RESPONSE_UNSOLICITED);
4291 p.writeInt32 (unsolResponse);
4292
4293 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004294 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004295 if (ret != 0) {
4296 // Problem with the response. Don't continue;
4297 goto error_exit;
4298 }
4299
4300 // some things get more payload
4301 switch(unsolResponse) {
4302 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004303 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004304 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004305 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004306 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004307 break;
4308
4309
4310 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4311 // Store the time that this was received so the
4312 // handler of this message can account for
4313 // the time it takes to arrive and process. In
4314 // particular the system has been known to sleep
4315 // before this message can be processed.
4316 p.writeInt64(timeReceived);
4317 break;
4318 }
4319
Etan Cohend3652192014-06-20 08:28:44 -07004320 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4321 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004322 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4323
4324 // Unfortunately, NITZ time is not poll/update like everything
4325 // else in the system. So, if the upstream client isn't connected,
4326 // keep a copy of the last NITZ response (with receive time noted
4327 // above) around so we can deliver it when it is connected
4328
4329 if (s_lastNITZTimeData != NULL) {
4330 free (s_lastNITZTimeData);
4331 s_lastNITZTimeData = NULL;
4332 }
4333
4334 s_lastNITZTimeData = malloc(p.dataSize());
4335 s_lastNITZTimeDataSize = p.dataSize();
4336 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4337 }
4338
4339 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4340 // FIXME The java code should handshake here to release wake lock
4341
4342 if (shouldScheduleTimeout) {
4343 // Cancel the previous request
4344 if (s_last_wake_timeout_info != NULL) {
4345 s_last_wake_timeout_info->userParam = (void *)1;
4346 }
4347
4348 s_last_wake_timeout_info
4349 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4350 &TIMEVAL_WAKE_TIMEOUT);
4351 }
4352
4353 // Normal exit
4354 return;
4355
4356error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004357 if (shouldScheduleTimeout) {
4358 releaseWakeLock();
4359 }
4360}
4361
Wink Saville7f856802009-06-09 10:23:37 -07004362/** FIXME generalize this if you track UserCAllbackInfo, clear it
4363 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004364*/
4365static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004366internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004367 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004368{
4369 struct timeval myRelativeTime;
4370 UserCallbackInfo *p_info;
4371
4372 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4373
Wink Saville7f856802009-06-09 10:23:37 -07004374 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004375 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004376
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004377 if (relativeTime == NULL) {
4378 /* treat null parameter as a 0 relative time */
4379 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4380 } else {
4381 /* FIXME I think event_add's tv param is really const anyway */
4382 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4383 }
4384
4385 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4386
4387 ril_timer_add(&(p_info->event), &myRelativeTime);
4388
4389 triggerEvLoop();
4390 return p_info;
4391}
4392
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004393
4394extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004395RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4396 const struct timeval *relativeTime) {
4397 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004398}
4399
4400const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004401failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402 switch(e) {
4403 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004404 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004405 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4406 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4407 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4408 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4409 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4410 case RIL_E_CANCELLED: return "E_CANCELLED";
4411 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4412 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4413 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004414 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004415 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004416#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004417 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4418 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4419#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004420 default: return "<unknown error>";
4421 }
4422}
4423
4424const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004425radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004426 switch(s) {
4427 case RADIO_STATE_OFF: return "RADIO_OFF";
4428 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4429 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4430 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4431 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004432 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4433 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4434 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4435 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4436 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004437 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004438 default: return "<unknown state>";
4439 }
4440}
4441
4442const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004443callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004444 switch(s) {
4445 case RIL_CALL_ACTIVE : return "ACTIVE";
4446 case RIL_CALL_HOLDING: return "HOLDING";
4447 case RIL_CALL_DIALING: return "DIALING";
4448 case RIL_CALL_ALERTING: return "ALERTING";
4449 case RIL_CALL_INCOMING: return "INCOMING";
4450 case RIL_CALL_WAITING: return "WAITING";
4451 default: return "<unknown state>";
4452 }
4453}
4454
4455const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004456requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004457/*
4458 cat libs/telephony/ril_commands.h \
4459 | egrep "^ *{RIL_" \
4460 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4461
4462
4463 cat libs/telephony/ril_unsol_commands.h \
4464 | egrep "^ *{RIL_" \
4465 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4466
4467*/
4468 switch(request) {
4469 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4470 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4471 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4472 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4473 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4474 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4475 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4476 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4477 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4478 case RIL_REQUEST_DIAL: return "DIAL";
4479 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4480 case RIL_REQUEST_HANGUP: return "HANGUP";
4481 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4482 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4483 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4484 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4485 case RIL_REQUEST_UDUB: return "UDUB";
4486 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4487 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004488 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4489 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004490 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4491 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4492 case RIL_REQUEST_DTMF: return "DTMF";
4493 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4494 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004495 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004496 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4497 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4498 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4499 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4500 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4501 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4502 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4503 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4504 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4505 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4506 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4507 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4508 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004509 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004510 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4511 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4512 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4513 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4514 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4515 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4516 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4517 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4518 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4519 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4520 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4521 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4522 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4523 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4524 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4525 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4526 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004527 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4528 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004529 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4530 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4531 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004532 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4533 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004534 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4535 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4536 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4537 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4538 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4539 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4540 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4541 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004542 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004543 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4544 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4545 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4546 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4547 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4548 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4549 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4550 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4551 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4552 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004553 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4554 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4555 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4556 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4557 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004558 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004559 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4560 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4561 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4562 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004563 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4564 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4565 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004566 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004567 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004568 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004569 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004570 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4571 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004572 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004573 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4574 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004575 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004576 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4577 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004578 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4579 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4580 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4581 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Etan Cohend3652192014-06-20 08:28:44 -07004582 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4583 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004584 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4585 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004586 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4587 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004588 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4589 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004590 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 -08004591 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4592 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4593 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4594 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4595 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4596 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4597 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4598 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4599 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4600 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4601 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4602 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4603 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004604 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004605 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004606 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4607 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4608 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4609 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004610 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4611 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4612 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4613 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4614 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004615 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004616 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004617 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004618 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004619 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4620 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004621 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004622 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004623 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004624 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004625 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4626 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4627 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004628 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004629 default: return "<unknown request>";
4630 }
4631}
4632
Etan Cohend3652192014-06-20 08:28:44 -07004633const char *
4634rilSocketIdToString(RIL_SOCKET_ID socket_id)
4635{
4636 switch(socket_id) {
4637 case RIL_SOCKET_1:
4638 return "RIL_SOCKET_1";
4639#if (SIM_COUNT >= 2)
4640 case RIL_SOCKET_2:
4641 return "RIL_SOCKET_2";
4642#endif
4643#if (SIM_COUNT >= 3)
4644 case RIL_SOCKET_3:
4645 return "RIL_SOCKET_3";
4646#endif
4647#if (SIM_COUNT >= 4)
4648 case RIL_SOCKET_4:
4649 return "RIL_SOCKET_4";
4650#endif
4651 default:
4652 return "not a valid RIL";
4653 }
4654}
4655
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004656} /* namespace android */