blob: bccc8d2df9de5430241c078100640d6d39c9c7fe [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);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800278static int responseInts(Parcel &p, void *response, size_t responselen);
279static int responseStrings(Parcel &p, void *response, size_t responselen);
280static int responseString(Parcel &p, void *response, size_t responselen);
281static int responseVoid(Parcel &p, void *response, size_t responselen);
282static int responseCallList(Parcel &p, void *response, size_t responselen);
283static int responseSMS(Parcel &p, void *response, size_t responselen);
284static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
285static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700286static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800287static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800288static int responseRaw(Parcel &p, void *response, size_t responselen);
289static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700290static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700291static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
292static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800294static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700295static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
296static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
297static int responseCallRing(Parcel &p, void *response, size_t responselen);
298static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
299static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800300static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700301static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700302static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700303static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800304
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800305static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
306static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
307static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
308
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800309#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700310#if defined(ANDROID_MULTI_SIM)
311extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
312 size_t datalen, RIL_SOCKET_ID socket_id);
313#else
Wink Saville7f856802009-06-09 10:23:37 -0700314extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800315 size_t datalen);
316#endif
Etan Cohend3652192014-06-20 08:28:44 -0700317#endif
318
319#if defined(ANDROID_MULTI_SIM)
320#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
321#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
322#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
323#else
324#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
325#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
326#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
327#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800328
Wink Saville7f856802009-06-09 10:23:37 -0700329static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700330 (RIL_TimedCallback callback, void *param,
331 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800332
333/** Index == requestNumber */
334static CommandInfo s_commands[] = {
335#include "ril_commands.h"
336};
337
338static UnsolResponseInfo s_unsolResponses[] = {
339#include "ril_unsol_commands.h"
340};
341
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800342/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
343 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
344 radio state message and store it. Every time there is a change in Radio State
345 check to see if voice radio tech changes and notify telephony
346 */
347int voiceRadioTech = -1;
348
349/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
350 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
351 source from radio state and store it. Every time there is a change in Radio State
352 check to see if subscription source changed and notify telephony
353 */
354int cdmaSubscriptionSource = -1;
355
356/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
357 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
358 check to see if SIM/RUIM status changed and notify telephony
359 */
360int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800361
Etan Cohend3652192014-06-20 08:28:44 -0700362static char * RIL_getRilSocketName() {
363 return rild;
364}
365
366extern "C"
367void RIL_setRilSocketName(char * s) {
368 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
369}
370
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800371static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700372strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373 size_t stringlen;
374 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700375
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800376 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378 return strndup16to8(s16, stringlen);
379}
380
Wink Savillef4c4d362009-04-02 01:37:03 -0700381static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800382 char16_t *s16;
383 size_t s16_len;
384 s16 = strdup8to16(s, &s16_len);
385 p.writeString16(s16, s16_len);
386 free(s16);
387}
388
389
390static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700391memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800392 if (s != NULL) {
393 memset (s, 0, strlen(s));
394 }
395}
396
397void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
398 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700399 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800400 // do nothing -- the data reference lives longer than the Parcel object
401}
402
Wink Saville7f856802009-06-09 10:23:37 -0700403/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800404 * To be called from dispatch thread
405 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700406 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800407 */
408static void
Etan Cohend3652192014-06-20 08:28:44 -0700409issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800410 RequestInfo *pRI;
411 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700412 /* Hook for current context */
413 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
414 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
415 /* pendingRequestsHook refer to &s_pendingRequests */
416 RequestInfo** pendingRequestsHook = &s_pendingRequests;
417
418#if (SIM_COUNT == 2)
419 if (socket_id == RIL_SOCKET_2) {
420 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
421 pendingRequestsHook = &s_pendingRequests_socket2;
422 }
423#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800424
425 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
426
427 pRI->local = 1;
428 pRI->token = 0xffffffff; // token is not used in this context
429 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700430 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431
Etan Cohend3652192014-06-20 08:28:44 -0700432 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433 assert (ret == 0);
434
Etan Cohend3652192014-06-20 08:28:44 -0700435 pRI->p_next = *pendingRequestsHook;
436 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437
Etan Cohend3652192014-06-20 08:28:44 -0700438 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800439 assert (ret == 0);
440
Wink Saville8eb2a122012-11-19 16:05:13 -0800441 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800442
Etan Cohend3652192014-06-20 08:28:44 -0700443 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800444}
445
446
447
448static int
Etan Cohend3652192014-06-20 08:28:44 -0700449processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800450 Parcel p;
451 status_t status;
452 int32_t request;
453 int32_t token;
454 RequestInfo *pRI;
455 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700456 /* Hook for current context */
457 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
458 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
459 /* pendingRequestsHook refer to &s_pendingRequests */
460 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800461
462 p.setData((uint8_t *) buffer, buflen);
463
464 // status checked at end
465 status = p.readInt32(&request);
466 status = p.readInt32 (&token);
467
Etan Cohend3652192014-06-20 08:28:44 -0700468 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
469
470#if (SIM_COUNT >= 2)
471 if (socket_id == RIL_SOCKET_2) {
472 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
473 pendingRequestsHook = &s_pendingRequests_socket2;
474 }
475#if (SIM_COUNT >= 3)
476 else if (socket_id == RIL_SOCKET_3) {
477 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
478 pendingRequestsHook = &s_pendingRequests_socket3;
479 }
480#endif
481#if (SIM_COUNT >= 4)
482 else if (socket_id == RIL_SOCKET_4) {
483 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
484 pendingRequestsHook = &s_pendingRequests_socket4;
485 }
486#endif
487#endif
488
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800489 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800490 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800491 return 0;
492 }
493
494 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700495 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800496 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800497 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700498 pErr.writeInt32 (RESPONSE_SOLICITED);
499 pErr.writeInt32 (token);
500 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
501
502 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800503 return 0;
504 }
505
506
507 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
508
509 pRI->token = token;
510 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700511 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800512
Etan Cohend3652192014-06-20 08:28:44 -0700513 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514 assert (ret == 0);
515
Etan Cohend3652192014-06-20 08:28:44 -0700516 pRI->p_next = *pendingRequestsHook;
517 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800518
Etan Cohend3652192014-06-20 08:28:44 -0700519 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520 assert (ret == 0);
521
522/* sLastDispatchedToken = token; */
523
Wink Saville7f856802009-06-09 10:23:37 -0700524 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800525
526 return 0;
527}
528
529static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700530invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800531 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800532 pRI->token, requestToString(pRI->pCI->requestNumber));
533}
534
535/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700536static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700537dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800538 clearPrintBuf;
539 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700540 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541}
542
543/** Callee expects const char * */
544static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700545dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800546 status_t status;
547 size_t datalen;
548 size_t stringlen;
549 char *string8 = NULL;
550
551 string8 = strdupReadString(p);
552
553 startRequest;
554 appendPrintBuf("%s%s", printBuf, string8);
555 closeRequest;
556 printRequest(pRI->token, pRI->pCI->requestNumber);
557
Etan Cohend3652192014-06-20 08:28:44 -0700558 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
559 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800560
561#ifdef MEMSET_FREED
562 memsetString(string8);
563#endif
564
565 free(string8);
566 return;
567invalid:
568 invalidCommandBlock(pRI);
569 return;
570}
571
572/** Callee expects const char ** */
573static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700574dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800575 int32_t countStrings;
576 status_t status;
577 size_t datalen;
578 char **pStrings;
579
580 status = p.readInt32 (&countStrings);
581
582 if (status != NO_ERROR) {
583 goto invalid;
584 }
585
586 startRequest;
587 if (countStrings == 0) {
588 // just some non-null pointer
589 pStrings = (char **)alloca(sizeof(char *));
590 datalen = 0;
591 } else if (((int)countStrings) == -1) {
592 pStrings = NULL;
593 datalen = 0;
594 } else {
595 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700596
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800597 pStrings = (char **)alloca(datalen);
598
599 for (int i = 0 ; i < countStrings ; i++) {
600 pStrings[i] = strdupReadString(p);
601 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
602 }
603 }
604 removeLastChar;
605 closeRequest;
606 printRequest(pRI->token, pRI->pCI->requestNumber);
607
Etan Cohend3652192014-06-20 08:28:44 -0700608 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800609
610 if (pStrings != NULL) {
611 for (int i = 0 ; i < countStrings ; i++) {
612#ifdef MEMSET_FREED
613 memsetString (pStrings[i]);
614#endif
615 free(pStrings[i]);
616 }
617
618#ifdef MEMSET_FREED
619 memset(pStrings, 0, datalen);
620#endif
621 }
Wink Saville7f856802009-06-09 10:23:37 -0700622
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800623 return;
624invalid:
625 invalidCommandBlock(pRI);
626 return;
627}
628
629/** Callee expects const int * */
630static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700631dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800632 int32_t count;
633 status_t status;
634 size_t datalen;
635 int *pInts;
636
637 status = p.readInt32 (&count);
638
639 if (status != NO_ERROR || count == 0) {
640 goto invalid;
641 }
642
643 datalen = sizeof(int) * count;
644 pInts = (int *)alloca(datalen);
645
646 startRequest;
647 for (int i = 0 ; i < count ; i++) {
648 int32_t t;
649
650 status = p.readInt32(&t);
651 pInts[i] = (int)t;
652 appendPrintBuf("%s%d,", printBuf, t);
653
654 if (status != NO_ERROR) {
655 goto invalid;
656 }
657 }
658 removeLastChar;
659 closeRequest;
660 printRequest(pRI->token, pRI->pCI->requestNumber);
661
Etan Cohend3652192014-06-20 08:28:44 -0700662 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
663 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800664
665#ifdef MEMSET_FREED
666 memset(pInts, 0, datalen);
667#endif
668
669 return;
670invalid:
671 invalidCommandBlock(pRI);
672 return;
673}
674
675
Wink Saville7f856802009-06-09 10:23:37 -0700676/**
677 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800678 * Payload is:
679 * int32_t status
680 * String pdu
681 */
682static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700683dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800684 RIL_SMS_WriteArgs args;
685 int32_t t;
686 status_t status;
687
688 memset (&args, 0, sizeof(args));
689
690 status = p.readInt32(&t);
691 args.status = (int)t;
692
693 args.pdu = strdupReadString(p);
694
695 if (status != NO_ERROR || args.pdu == NULL) {
696 goto invalid;
697 }
698
699 args.smsc = strdupReadString(p);
700
701 startRequest;
702 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
703 (char*)args.pdu, (char*)args.smsc);
704 closeRequest;
705 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700706
Etan Cohend3652192014-06-20 08:28:44 -0700707 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800708
709#ifdef MEMSET_FREED
710 memsetString (args.pdu);
711#endif
712
713 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700714
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800715#ifdef MEMSET_FREED
716 memset(&args, 0, sizeof(args));
717#endif
718
719 return;
720invalid:
721 invalidCommandBlock(pRI);
722 return;
723}
724
Wink Saville7f856802009-06-09 10:23:37 -0700725/**
726 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800727 * Payload is:
728 * String address
729 * int32_t clir
730 */
731static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700732dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800733 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800734 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800735 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800736 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800737 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800738 status_t status;
739
740 memset (&dial, 0, sizeof(dial));
741
742 dial.address = strdupReadString(p);
743
744 status = p.readInt32(&t);
745 dial.clir = (int)t;
746
747 if (status != NO_ERROR || dial.address == NULL) {
748 goto invalid;
749 }
750
Wink Saville3a4840b2010-04-07 13:29:58 -0700751 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800752 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800753 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800754 } else {
755 status = p.readInt32(&uusPresent);
756
757 if (status != NO_ERROR) {
758 goto invalid;
759 }
760
761 if (uusPresent == 0) {
762 dial.uusInfo = NULL;
763 } else {
764 int32_t len;
765
766 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
767
768 status = p.readInt32(&t);
769 uusInfo.uusType = (RIL_UUS_Type) t;
770
771 status = p.readInt32(&t);
772 uusInfo.uusDcs = (RIL_UUS_DCS) t;
773
774 status = p.readInt32(&len);
775 if (status != NO_ERROR) {
776 goto invalid;
777 }
778
779 // The java code writes -1 for null arrays
780 if (((int) len) == -1) {
781 uusInfo.uusData = NULL;
782 len = 0;
783 } else {
784 uusInfo.uusData = (char*) p.readInplace(len);
785 }
786
787 uusInfo.uusLength = len;
788 dial.uusInfo = &uusInfo;
789 }
Wink Saville7bce0822010-01-08 15:20:12 -0800790 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800791 }
792
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800793 startRequest;
794 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800795 if (uusPresent) {
796 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
797 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
798 dial.uusInfo->uusLength);
799 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800800 closeRequest;
801 printRequest(pRI->token, pRI->pCI->requestNumber);
802
Etan Cohend3652192014-06-20 08:28:44 -0700803 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800804
805#ifdef MEMSET_FREED
806 memsetString (dial.address);
807#endif
808
809 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700810
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800811#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800812 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800813 memset(&dial, 0, sizeof(dial));
814#endif
815
816 return;
817invalid:
818 invalidCommandBlock(pRI);
819 return;
820}
821
Wink Saville7f856802009-06-09 10:23:37 -0700822/**
823 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800824 * Payload is:
825 * int32_t command
826 * int32_t fileid
827 * String path
828 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700829 * String data
830 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800831 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800832 */
833static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700834dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800835 union RIL_SIM_IO {
836 RIL_SIM_IO_v6 v6;
837 RIL_SIM_IO_v5 v5;
838 } simIO;
839
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800840 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800841 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800842 status_t status;
843
844 memset (&simIO, 0, sizeof(simIO));
845
Wink Saville7f856802009-06-09 10:23:37 -0700846 // note we only check status at the end
847
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800848 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800849 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800850
851 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800852 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800853
Wink Savillec0114b32011-02-18 10:14:07 -0800854 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855
856 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800857 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800858
859 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800860 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800861
862 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800863 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800864
Wink Savillec0114b32011-02-18 10:14:07 -0800865 simIO.v6.data = strdupReadString(p);
866 simIO.v6.pin2 = strdupReadString(p);
867 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800868
869 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800870 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
871 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
872 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
873 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874 closeRequest;
875 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700876
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877 if (status != NO_ERROR) {
878 goto invalid;
879 }
880
Wink Savillec0114b32011-02-18 10:14:07 -0800881 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700882 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800883
884#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800885 memsetString (simIO.v6.path);
886 memsetString (simIO.v6.data);
887 memsetString (simIO.v6.pin2);
888 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800889#endif
890
Wink Savillec0114b32011-02-18 10:14:07 -0800891 free (simIO.v6.path);
892 free (simIO.v6.data);
893 free (simIO.v6.pin2);
894 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700895
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800896#ifdef MEMSET_FREED
897 memset(&simIO, 0, sizeof(simIO));
898#endif
899
900 return;
901invalid:
902 invalidCommandBlock(pRI);
903 return;
904}
905
906/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800907 * Callee expects const RIL_SIM_APDU *
908 * Payload is:
909 * int32_t sessionid
910 * int32_t cla
911 * int32_t instruction
912 * int32_t p1, p2, p3
913 * String data
914 */
915static void
916dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
917 int32_t t;
918 status_t status;
919 RIL_SIM_APDU apdu;
920
921 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
922
923 // Note we only check status at the end. Any single failure leads to
924 // subsequent reads filing.
925 status = p.readInt32(&t);
926 apdu.sessionid = (int)t;
927
928 status = p.readInt32(&t);
929 apdu.cla = (int)t;
930
931 status = p.readInt32(&t);
932 apdu.instruction = (int)t;
933
934 status = p.readInt32(&t);
935 apdu.p1 = (int)t;
936
937 status = p.readInt32(&t);
938 apdu.p2 = (int)t;
939
940 status = p.readInt32(&t);
941 apdu.p3 = (int)t;
942
943 apdu.data = strdupReadString(p);
944
945 startRequest;
946 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
947 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
948 apdu.p3, (char*)apdu.data);
949 closeRequest;
950 printRequest(pRI->token, pRI->pCI->requestNumber);
951
952 if (status != NO_ERROR) {
953 goto invalid;
954 }
955
Etan Cohend3652192014-06-20 08:28:44 -0700956 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800957
958#ifdef MEMSET_FREED
959 memsetString(apdu.data);
960#endif
961 free(apdu.data);
962
963#ifdef MEMSET_FREED
964 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
965#endif
966
967 return;
968invalid:
969 invalidCommandBlock(pRI);
970 return;
971}
972
973
974/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800975 * Callee expects const RIL_CallForwardInfo *
976 * Payload is:
977 * int32_t status/action
978 * int32_t reason
979 * int32_t serviceCode
980 * int32_t toa
981 * String number (0 length -> null)
982 * int32_t timeSeconds
983 */
Wink Saville7f856802009-06-09 10:23:37 -0700984static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700985dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800986 RIL_CallForwardInfo cff;
987 int32_t t;
988 status_t status;
989
990 memset (&cff, 0, sizeof(cff));
991
Wink Saville7f856802009-06-09 10:23:37 -0700992 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800993
994 status = p.readInt32(&t);
995 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -0700996
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800997 status = p.readInt32(&t);
998 cff.reason = (int)t;
999
1000 status = p.readInt32(&t);
1001 cff.serviceClass = (int)t;
1002
1003 status = p.readInt32(&t);
1004 cff.toa = (int)t;
1005
1006 cff.number = strdupReadString(p);
1007
1008 status = p.readInt32(&t);
1009 cff.timeSeconds = (int)t;
1010
1011 if (status != NO_ERROR) {
1012 goto invalid;
1013 }
1014
1015 // special case: number 0-length fields is null
1016
1017 if (cff.number != NULL && strlen (cff.number) == 0) {
1018 cff.number = NULL;
1019 }
1020
1021 startRequest;
1022 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1023 cff.status, cff.reason, cff.serviceClass, cff.toa,
1024 (char*)cff.number, cff.timeSeconds);
1025 closeRequest;
1026 printRequest(pRI->token, pRI->pCI->requestNumber);
1027
Etan Cohend3652192014-06-20 08:28:44 -07001028 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001029
1030#ifdef MEMSET_FREED
1031 memsetString(cff.number);
1032#endif
1033
1034 free (cff.number);
1035
1036#ifdef MEMSET_FREED
1037 memset(&cff, 0, sizeof(cff));
1038#endif
1039
1040 return;
1041invalid:
1042 invalidCommandBlock(pRI);
1043 return;
1044}
1045
1046
Wink Saville7f856802009-06-09 10:23:37 -07001047static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001048dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001049 int32_t len;
1050 status_t status;
1051 const void *data;
1052
1053 status = p.readInt32(&len);
1054
1055 if (status != NO_ERROR) {
1056 goto invalid;
1057 }
1058
1059 // The java code writes -1 for null arrays
1060 if (((int)len) == -1) {
1061 data = NULL;
1062 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001063 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001064
1065 data = p.readInplace(len);
1066
1067 startRequest;
1068 appendPrintBuf("%sraw_size=%d", printBuf, len);
1069 closeRequest;
1070 printRequest(pRI->token, pRI->pCI->requestNumber);
1071
Etan Cohend3652192014-06-20 08:28:44 -07001072 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001073
1074 return;
1075invalid:
1076 invalidCommandBlock(pRI);
1077 return;
1078}
1079
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001080static status_t
1081constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001082 int32_t t;
1083 uint8_t ut;
1084 status_t status;
1085 int32_t digitCount;
1086 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001087
Wink Savillef4c4d362009-04-02 01:37:03 -07001088 memset(&rcsm, 0, sizeof(rcsm));
1089
1090 status = p.readInt32(&t);
1091 rcsm.uTeleserviceID = (int) t;
1092
1093 status = p.read(&ut,sizeof(ut));
1094 rcsm.bIsServicePresent = (uint8_t) ut;
1095
1096 status = p.readInt32(&t);
1097 rcsm.uServicecategory = (int) t;
1098
1099 status = p.readInt32(&t);
1100 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1101
1102 status = p.readInt32(&t);
1103 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1104
1105 status = p.readInt32(&t);
1106 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1107
1108 status = p.readInt32(&t);
1109 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1110
1111 status = p.read(&ut,sizeof(ut));
1112 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1113
1114 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1115 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1116 status = p.read(&ut,sizeof(ut));
1117 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1118 }
1119
Wink Saville7f856802009-06-09 10:23:37 -07001120 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001121 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1122
Wink Saville7f856802009-06-09 10:23:37 -07001123 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001124 rcsm.sSubAddress.odd = (uint8_t) ut;
1125
1126 status = p.read(&ut,sizeof(ut));
1127 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1128
1129 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001130 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1131 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001132 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1133 }
1134
Wink Saville7f856802009-06-09 10:23:37 -07001135 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001136 rcsm.uBearerDataLen = (int) t;
1137
1138 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001139 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1140 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001141 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1142 }
1143
1144 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001145 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001146 }
1147
1148 startRequest;
1149 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001150 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001151 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001152 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001153 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001154
Wink Savillef4c4d362009-04-02 01:37:03 -07001155 printRequest(pRI->token, pRI->pCI->requestNumber);
1156
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001157 return status;
1158}
1159
1160static void
1161dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1162 RIL_CDMA_SMS_Message rcsm;
1163
1164 ALOGD("dispatchCdmaSms");
1165 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1166 goto invalid;
1167 }
1168
Etan Cohend3652192014-06-20 08:28:44 -07001169 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001170
1171#ifdef MEMSET_FREED
1172 memset(&rcsm, 0, sizeof(rcsm));
1173#endif
1174
1175 return;
1176
1177invalid:
1178 invalidCommandBlock(pRI);
1179 return;
1180}
1181
Wink Saville7f856802009-06-09 10:23:37 -07001182static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001183dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1184 RIL_IMS_SMS_Message rism;
1185 RIL_CDMA_SMS_Message rcsm;
1186
1187 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1188
1189 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1190 goto invalid;
1191 }
1192 memset(&rism, 0, sizeof(rism));
1193 rism.tech = RADIO_TECH_3GPP2;
1194 rism.retry = retry;
1195 rism.messageRef = messageRef;
1196 rism.message.cdmaMessage = &rcsm;
1197
Etan Cohend3652192014-06-20 08:28:44 -07001198 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001199 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001200 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001201
1202#ifdef MEMSET_FREED
1203 memset(&rcsm, 0, sizeof(rcsm));
1204 memset(&rism, 0, sizeof(rism));
1205#endif
1206
1207 return;
1208
1209invalid:
1210 invalidCommandBlock(pRI);
1211 return;
1212}
1213
1214static void
1215dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1216 RIL_IMS_SMS_Message rism;
1217 int32_t countStrings;
1218 status_t status;
1219 size_t datalen;
1220 char **pStrings;
1221 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1222
1223 status = p.readInt32 (&countStrings);
1224
1225 if (status != NO_ERROR) {
1226 goto invalid;
1227 }
1228
1229 memset(&rism, 0, sizeof(rism));
1230 rism.tech = RADIO_TECH_3GPP;
1231 rism.retry = retry;
1232 rism.messageRef = messageRef;
1233
1234 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001235 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1236 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001237 if (countStrings == 0) {
1238 // just some non-null pointer
1239 pStrings = (char **)alloca(sizeof(char *));
1240 datalen = 0;
1241 } else if (((int)countStrings) == -1) {
1242 pStrings = NULL;
1243 datalen = 0;
1244 } else {
1245 datalen = sizeof(char *) * countStrings;
1246
1247 pStrings = (char **)alloca(datalen);
1248
1249 for (int i = 0 ; i < countStrings ; i++) {
1250 pStrings[i] = strdupReadString(p);
1251 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1252 }
1253 }
1254 removeLastChar;
1255 closeRequest;
1256 printRequest(pRI->token, pRI->pCI->requestNumber);
1257
1258 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001259 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001260 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001261 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001262
1263 if (pStrings != NULL) {
1264 for (int i = 0 ; i < countStrings ; i++) {
1265#ifdef MEMSET_FREED
1266 memsetString (pStrings[i]);
1267#endif
1268 free(pStrings[i]);
1269 }
1270
1271#ifdef MEMSET_FREED
1272 memset(pStrings, 0, datalen);
1273#endif
1274 }
1275
1276#ifdef MEMSET_FREED
1277 memset(&rism, 0, sizeof(rism));
1278#endif
1279 return;
1280invalid:
1281 ALOGE("dispatchImsGsmSms invalid block");
1282 invalidCommandBlock(pRI);
1283 return;
1284}
1285
1286static void
1287dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1288 int32_t t;
1289 status_t status = p.readInt32(&t);
1290 RIL_RadioTechnologyFamily format;
1291 uint8_t retry;
1292 int32_t messageRef;
1293
1294 ALOGD("dispatchImsSms");
1295 if (status != NO_ERROR) {
1296 goto invalid;
1297 }
1298 format = (RIL_RadioTechnologyFamily) t;
1299
1300 // read retry field
1301 status = p.read(&retry,sizeof(retry));
1302 if (status != NO_ERROR) {
1303 goto invalid;
1304 }
1305 // read messageRef field
1306 status = p.read(&messageRef,sizeof(messageRef));
1307 if (status != NO_ERROR) {
1308 goto invalid;
1309 }
1310
1311 if (RADIO_TECH_3GPP == format) {
1312 dispatchImsGsmSms(p, pRI, retry, messageRef);
1313 } else if (RADIO_TECH_3GPP2 == format) {
1314 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1315 } else {
1316 ALOGE("requestImsSendSMS invalid format value =%d", format);
1317 }
1318
1319 return;
1320
1321invalid:
1322 invalidCommandBlock(pRI);
1323 return;
1324}
1325
1326static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001327dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1328 RIL_CDMA_SMS_Ack rcsa;
1329 int32_t t;
1330 status_t status;
1331 int32_t digitCount;
1332
1333 memset(&rcsa, 0, sizeof(rcsa));
1334
1335 status = p.readInt32(&t);
1336 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1337
1338 status = p.readInt32(&t);
1339 rcsa.uSMSCauseCode = (int) t;
1340
1341 if (status != NO_ERROR) {
1342 goto invalid;
1343 }
1344
1345 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001346 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1347 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001348 closeRequest;
1349
1350 printRequest(pRI->token, pRI->pCI->requestNumber);
1351
Etan Cohend3652192014-06-20 08:28:44 -07001352 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001353
1354#ifdef MEMSET_FREED
1355 memset(&rcsa, 0, sizeof(rcsa));
1356#endif
1357
1358 return;
1359
1360invalid:
1361 invalidCommandBlock(pRI);
1362 return;
1363}
1364
Wink Savillea592eeb2009-05-22 13:26:36 -07001365static void
1366dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1367 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001368 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001369 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001370
Wink Savillea592eeb2009-05-22 13:26:36 -07001371 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001372 if (status != NO_ERROR) {
1373 goto invalid;
1374 }
1375
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001376 {
1377 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1378 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001379
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001380 startRequest;
1381 for (int i = 0 ; i < num ; i++ ) {
1382 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001383
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001384 status = p.readInt32(&t);
1385 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001386
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001387 status = p.readInt32(&t);
1388 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001389
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001390 status = p.readInt32(&t);
1391 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001392
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001393 status = p.readInt32(&t);
1394 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001395
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001396 status = p.readInt32(&t);
1397 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001398
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001399 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1400 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1401 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1402 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1403 gsmBci[i].selected);
1404 }
1405 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001406
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001407 if (status != NO_ERROR) {
1408 goto invalid;
1409 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001410
Etan Cohend3652192014-06-20 08:28:44 -07001411 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001412 gsmBciPtrs,
1413 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001414 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001415
1416#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001417 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1418 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001419#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
1422 return;
1423
1424invalid:
1425 invalidCommandBlock(pRI);
1426 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001427}
Wink Savillef4c4d362009-04-02 01:37:03 -07001428
Wink Savillea592eeb2009-05-22 13:26:36 -07001429static void
1430dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1431 int32_t t;
1432 status_t status;
1433 int32_t num;
1434
1435 status = p.readInt32(&num);
1436 if (status != NO_ERROR) {
1437 goto invalid;
1438 }
1439
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001440 {
1441 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1442 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001443
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001444 startRequest;
1445 for (int i = 0 ; i < num ; i++ ) {
1446 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001447
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001448 status = p.readInt32(&t);
1449 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001450
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001451 status = p.readInt32(&t);
1452 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001453
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001454 status = p.readInt32(&t);
1455 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001456
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001457 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1458 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1459 cdmaBci[i].language, cdmaBci[i].selected);
1460 }
1461 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001462
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001463 if (status != NO_ERROR) {
1464 goto invalid;
1465 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001466
Etan Cohend3652192014-06-20 08:28:44 -07001467 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001468 cdmaBciPtrs,
1469 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001470 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001471
1472#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001473 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1474 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001475#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
1478 return;
1479
1480invalid:
1481 invalidCommandBlock(pRI);
1482 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001483}
1484
1485static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1486 RIL_CDMA_SMS_WriteArgs rcsw;
1487 int32_t t;
1488 uint32_t ut;
1489 uint8_t uct;
1490 status_t status;
1491 int32_t digitCount;
1492
1493 memset(&rcsw, 0, sizeof(rcsw));
1494
1495 status = p.readInt32(&t);
1496 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001497
Wink Savillef4c4d362009-04-02 01:37:03 -07001498 status = p.readInt32(&t);
1499 rcsw.message.uTeleserviceID = (int) t;
1500
1501 status = p.read(&uct,sizeof(uct));
1502 rcsw.message.bIsServicePresent = (uint8_t) uct;
1503
1504 status = p.readInt32(&t);
1505 rcsw.message.uServicecategory = (int) t;
1506
1507 status = p.readInt32(&t);
1508 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1509
1510 status = p.readInt32(&t);
1511 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1512
1513 status = p.readInt32(&t);
1514 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1515
1516 status = p.readInt32(&t);
1517 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1518
1519 status = p.read(&uct,sizeof(uct));
1520 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1521
1522 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1523 status = p.read(&uct,sizeof(uct));
1524 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1525 }
1526
Wink Savillea592eeb2009-05-22 13:26:36 -07001527 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001528 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1529
Wink Savillea592eeb2009-05-22 13:26:36 -07001530 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001531 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1532
1533 status = p.read(&uct,sizeof(uct));
1534 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1535
1536 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001537 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001538 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1539 }
1540
Wink Savillea592eeb2009-05-22 13:26:36 -07001541 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001542 rcsw.message.uBearerDataLen = (int) t;
1543
1544 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001545 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001546 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1547 }
1548
1549 if (status != NO_ERROR) {
1550 goto invalid;
1551 }
1552
1553 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001554 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1555 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1556 message.sAddress.number_mode=%d, \
1557 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001558 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001559 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1560 rcsw.message.sAddress.number_mode,
1561 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001562 closeRequest;
1563
1564 printRequest(pRI->token, pRI->pCI->requestNumber);
1565
Etan Cohend3652192014-06-20 08:28:44 -07001566 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001567
1568#ifdef MEMSET_FREED
1569 memset(&rcsw, 0, sizeof(rcsw));
1570#endif
1571
1572 return;
1573
1574invalid:
1575 invalidCommandBlock(pRI);
1576 return;
1577
1578}
1579
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001580// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1581// Version 4 of the RIL interface adds a new PDP type parameter to support
1582// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1583// RIL, remove the parameter from the request.
1584static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1585 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1586 const int numParamsRilV3 = 6;
1587
1588 // The first bytes of the RIL parcel contain the request number and the
1589 // serial number - see processCommandBuffer(). Copy them over too.
1590 int pos = p.dataPosition();
1591
1592 int numParams = p.readInt32();
1593 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1594 Parcel p2;
1595 p2.appendFrom(&p, 0, pos);
1596 p2.writeInt32(numParamsRilV3);
1597 for(int i = 0; i < numParamsRilV3; i++) {
1598 p2.writeString16(p.readString16());
1599 }
1600 p2.setDataPosition(pos);
1601 dispatchStrings(p2, pRI);
1602 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001603 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001604 dispatchStrings(p, pRI);
1605 }
1606}
1607
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001608// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1609// When all RILs handle this request, this function can be removed and
1610// the request can be sent directly to the RIL using dispatchVoid.
1611static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001612 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001613
1614 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1615 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1616 }
1617
1618 // RILs that support RADIO_STATE_ON should support this request.
1619 if (RADIO_STATE_ON == state) {
1620 dispatchVoid(p, pRI);
1621 return;
1622 }
1623
1624 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1625 // will not support this new request either and decode Voice Radio Technology
1626 // from Radio State
1627 voiceRadioTech = decodeVoiceRadioTechnology(state);
1628
1629 if (voiceRadioTech < 0)
1630 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1631 else
1632 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1633}
1634
1635// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1636// When all RILs handle this request, this function can be removed and
1637// the request can be sent directly to the RIL using dispatchVoid.
1638static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001639 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001640
1641 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1642 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1643 }
1644
1645 // RILs that support RADIO_STATE_ON should support this request.
1646 if (RADIO_STATE_ON == state) {
1647 dispatchVoid(p, pRI);
1648 return;
1649 }
1650
1651 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1652 // will not support this new request either and decode CDMA Subscription Source
1653 // from Radio State
1654 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1655
1656 if (cdmaSubscriptionSource < 0)
1657 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1658 else
1659 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1660}
1661
Sungmin Choi75697532013-04-26 15:04:45 -07001662static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1663{
1664 RIL_InitialAttachApn pf;
1665 int32_t t;
1666 status_t status;
1667
1668 memset(&pf, 0, sizeof(pf));
1669
1670 pf.apn = strdupReadString(p);
1671 pf.protocol = strdupReadString(p);
1672
1673 status = p.readInt32(&t);
1674 pf.authtype = (int) t;
1675
1676 pf.username = strdupReadString(p);
1677 pf.password = strdupReadString(p);
1678
1679 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001680 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1681 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001682 closeRequest;
1683 printRequest(pRI->token, pRI->pCI->requestNumber);
1684
1685 if (status != NO_ERROR) {
1686 goto invalid;
1687 }
Etan Cohend3652192014-06-20 08:28:44 -07001688 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001689
1690#ifdef MEMSET_FREED
1691 memsetString(pf.apn);
1692 memsetString(pf.protocol);
1693 memsetString(pf.username);
1694 memsetString(pf.password);
1695#endif
1696
1697 free(pf.apn);
1698 free(pf.protocol);
1699 free(pf.username);
1700 free(pf.password);
1701
1702#ifdef MEMSET_FREED
1703 memset(&pf, 0, sizeof(pf));
1704#endif
1705
1706 return;
1707invalid:
1708 invalidCommandBlock(pRI);
1709 return;
1710}
1711
Jake Hamby8a4a2332014-01-15 13:12:05 -08001712static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1713 RIL_NV_ReadItem nvri;
1714 int32_t t;
1715 status_t status;
1716
1717 memset(&nvri, 0, sizeof(nvri));
1718
1719 status = p.readInt32(&t);
1720 nvri.itemID = (RIL_NV_Item) t;
1721
1722 if (status != NO_ERROR) {
1723 goto invalid;
1724 }
1725
1726 startRequest;
1727 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1728 closeRequest;
1729
1730 printRequest(pRI->token, pRI->pCI->requestNumber);
1731
Etan Cohend3652192014-06-20 08:28:44 -07001732 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001733
1734#ifdef MEMSET_FREED
1735 memset(&nvri, 0, sizeof(nvri));
1736#endif
1737
1738 return;
1739
1740invalid:
1741 invalidCommandBlock(pRI);
1742 return;
1743}
1744
1745static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1746 RIL_NV_WriteItem nvwi;
1747 int32_t t;
1748 status_t status;
1749
1750 memset(&nvwi, 0, sizeof(nvwi));
1751
1752 status = p.readInt32(&t);
1753 nvwi.itemID = (RIL_NV_Item) t;
1754
1755 nvwi.value = strdupReadString(p);
1756
1757 if (status != NO_ERROR || nvwi.value == NULL) {
1758 goto invalid;
1759 }
1760
1761 startRequest;
1762 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1763 nvwi.value);
1764 closeRequest;
1765
1766 printRequest(pRI->token, pRI->pCI->requestNumber);
1767
Etan Cohend3652192014-06-20 08:28:44 -07001768 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001769
1770#ifdef MEMSET_FREED
1771 memsetString(nvwi.value);
1772#endif
1773
1774 free(nvwi.value);
1775
1776#ifdef MEMSET_FREED
1777 memset(&nvwi, 0, sizeof(nvwi));
1778#endif
1779
1780 return;
1781
1782invalid:
1783 invalidCommandBlock(pRI);
1784 return;
1785}
1786
1787
Etan Cohend3652192014-06-20 08:28:44 -07001788static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1789 RIL_SelectUiccSub uicc_sub;
1790 status_t status;
1791 int32_t t;
1792 memset(&uicc_sub, 0, sizeof(uicc_sub));
1793
1794 status = p.readInt32(&t);
1795 if (status != NO_ERROR) {
1796 goto invalid;
1797 }
1798 uicc_sub.slot = (int) t;
1799
1800 status = p.readInt32(&t);
1801 if (status != NO_ERROR) {
1802 goto invalid;
1803 }
1804 uicc_sub.app_index = (int) t;
1805
1806 status = p.readInt32(&t);
1807 if (status != NO_ERROR) {
1808 goto invalid;
1809 }
1810 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1811
1812 status = p.readInt32(&t);
1813 if (status != NO_ERROR) {
1814 goto invalid;
1815 }
1816 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1817
1818 startRequest;
1819 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1820 uicc_sub.act_status);
1821 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1822 uicc_sub.app_index, uicc_sub.act_status);
1823 closeRequest;
1824 printRequest(pRI->token, pRI->pCI->requestNumber);
1825
1826 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1827
1828#ifdef MEMSET_FREED
1829 memset(&uicc_sub, 0, sizeof(uicc_sub));
1830#endif
1831 return;
1832
1833invalid:
1834 invalidCommandBlock(pRI);
1835 return;
1836}
1837
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001838static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001839blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07001840 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001841 const uint8_t *toWrite;
1842
1843 toWrite = (const uint8_t *)buffer;
1844
1845 while (writeOffset < len) {
1846 ssize_t written;
1847 do {
1848 written = write (fd, toWrite + writeOffset,
1849 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05301850 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001851
1852 if (written >= 0) {
1853 writeOffset += written;
1854 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08001855 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001856 close(fd);
1857 return -1;
1858 }
1859 }
1860
1861 return 0;
1862}
1863
1864static int
Etan Cohend3652192014-06-20 08:28:44 -07001865sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1866 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001867 int ret;
1868 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07001869 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001870
Etan Cohend3652192014-06-20 08:28:44 -07001871 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1872
1873#if (SIM_COUNT >= 2)
1874 if (socket_id == RIL_SOCKET_2) {
1875 fd = s_ril_param_socket2.fdCommand;
1876 writeMutexHook = &s_writeMutex_socket2;
1877 }
1878#if (SIM_COUNT >= 3)
1879 else if (socket_id == RIL_SOCKET_3) {
1880 fd = s_ril_param_socket3.fdCommand;
1881 writeMutexHook = &s_writeMutex_socket3;
1882 }
1883#endif
1884#if (SIM_COUNT >= 4)
1885 else if (socket_id == RIL_SOCKET_4) {
1886 fd = s_ril_param_socket4.fdCommand;
1887 writeMutexHook = &s_writeMutex_socket4;
1888 }
1889#endif
1890#endif
1891 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001892 return -1;
1893 }
1894
1895 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001896 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001897 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1898
1899 return -1;
1900 }
Wink Saville7f856802009-06-09 10:23:37 -07001901
Etan Cohend3652192014-06-20 08:28:44 -07001902 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001903
1904 header = htonl(dataSize);
1905
1906 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1907
1908 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07001909 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001910 return ret;
1911 }
1912
Kennyee1fadc2009-08-13 00:45:53 +08001913 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001914
1915 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07001916 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001917 return ret;
1918 }
1919
Etan Cohend3652192014-06-20 08:28:44 -07001920 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001921
1922 return 0;
1923}
1924
1925static int
Etan Cohend3652192014-06-20 08:28:44 -07001926sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001927 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07001928 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001929}
1930
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07001931/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07001932
1933static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001934responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001935 int numInts;
1936
1937 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001938 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001939 return RIL_ERRNO_INVALID_RESPONSE;
1940 }
1941 if (responselen % sizeof(int) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001942 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001943 (int)responselen, (int)sizeof(int));
1944 return RIL_ERRNO_INVALID_RESPONSE;
1945 }
1946
1947 int *p_int = (int *) response;
1948
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07001949 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001950 p.writeInt32 (numInts);
1951
1952 /* each int*/
1953 startResponse;
1954 for (int i = 0 ; i < numInts ; i++) {
1955 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1956 p.writeInt32(p_int[i]);
1957 }
1958 removeLastChar;
1959 closeResponse;
1960
1961 return 0;
1962}
1963
Wink Saville43808972011-01-13 17:39:51 -08001964/** response is a char **, pointing to an array of char *'s
1965 The parcel will begin with the version */
1966static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1967 p.writeInt32(version);
1968 return responseStrings(p, response, responselen);
1969}
1970
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001971/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07001972static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001973 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07001974
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001975 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001976 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001977 return RIL_ERRNO_INVALID_RESPONSE;
1978 }
1979 if (responselen % sizeof(char *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001980 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001981 (int)responselen, (int)sizeof(char *));
1982 return RIL_ERRNO_INVALID_RESPONSE;
1983 }
1984
1985 if (response == NULL) {
1986 p.writeInt32 (0);
1987 } else {
1988 char **p_cur = (char **) response;
1989
1990 numStrings = responselen / sizeof(char *);
1991 p.writeInt32 (numStrings);
1992
1993 /* each string*/
1994 startResponse;
1995 for (int i = 0 ; i < numStrings ; i++) {
1996 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1997 writeStringToParcel (p, p_cur[i]);
1998 }
1999 removeLastChar;
2000 closeResponse;
2001 }
2002 return 0;
2003}
2004
2005
2006/**
Wink Saville7f856802009-06-09 10:23:37 -07002007 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002008 * FIXME currently ignores responselen
2009 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002010static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002011 /* one string only */
2012 startResponse;
2013 appendPrintBuf("%s%s", printBuf, (char*)response);
2014 closeResponse;
2015
2016 writeStringToParcel(p, (const char *)response);
2017
2018 return 0;
2019}
2020
Wink Savillef4c4d362009-04-02 01:37:03 -07002021static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002022 startResponse;
2023 removeLastChar;
2024 return 0;
2025}
2026
Wink Savillef4c4d362009-04-02 01:37:03 -07002027static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002028 int num;
2029
2030 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002031 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002032 return RIL_ERRNO_INVALID_RESPONSE;
2033 }
2034
2035 if (responselen % sizeof (RIL_Call *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002036 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002037 (int)responselen, (int)sizeof (RIL_Call *));
2038 return RIL_ERRNO_INVALID_RESPONSE;
2039 }
2040
2041 startResponse;
2042 /* number of call info's */
2043 num = responselen / sizeof(RIL_Call *);
2044 p.writeInt32(num);
2045
2046 for (int i = 0 ; i < num ; i++) {
2047 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2048 /* each call info */
2049 p.writeInt32(p_cur->state);
2050 p.writeInt32(p_cur->index);
2051 p.writeInt32(p_cur->toa);
2052 p.writeInt32(p_cur->isMpty);
2053 p.writeInt32(p_cur->isMT);
2054 p.writeInt32(p_cur->als);
2055 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002056 p.writeInt32(p_cur->isVoicePrivacy);
2057 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002058 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002059 writeStringToParcel(p, p_cur->name);
2060 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002061 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002062 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2063 p.writeInt32(0); /* UUS Information is absent */
2064 } else {
2065 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2066 p.writeInt32(1); /* UUS Information is present */
2067 p.writeInt32(uusInfo->uusType);
2068 p.writeInt32(uusInfo->uusDcs);
2069 p.writeInt32(uusInfo->uusLength);
2070 p.write(uusInfo->uusData, uusInfo->uusLength);
2071 }
Wink Saville3d54e742009-05-18 18:00:44 -07002072 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002073 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002074 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002075 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002076 p_cur->toa);
2077 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2078 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002079 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002080 (p_cur->isMT)?"mt":"mo",
2081 p_cur->als,
2082 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002083 (p_cur->isVoicePrivacy)?"evp":"noevp");
2084 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2085 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002086 p_cur->number,
2087 p_cur->numberPresentation,
2088 p_cur->name,
2089 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002090 }
2091 removeLastChar;
2092 closeResponse;
2093
2094 return 0;
2095}
2096
Wink Savillef4c4d362009-04-02 01:37:03 -07002097static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002098 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002099 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100 return RIL_ERRNO_INVALID_RESPONSE;
2101 }
2102
2103 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002104 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002105 (int)responselen, (int)sizeof (RIL_SMS_Response));
2106 return RIL_ERRNO_INVALID_RESPONSE;
2107 }
2108
2109 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2110
2111 p.writeInt32(p_cur->messageRef);
2112 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002113 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002114
2115 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002116 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2117 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118 closeResponse;
2119
2120 return 0;
2121}
2122
Wink Savillec0114b32011-02-18 10:14:07 -08002123static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124{
2125 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002126 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002127 return RIL_ERRNO_INVALID_RESPONSE;
2128 }
2129
Wink Savillec0114b32011-02-18 10:14:07 -08002130 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002131 RLOGE("invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002132 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002133 return RIL_ERRNO_INVALID_RESPONSE;
2134 }
2135
Wink Savillec0114b32011-02-18 10:14:07 -08002136 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002137 p.writeInt32(num);
2138
Wink Savillec0114b32011-02-18 10:14:07 -08002139 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002140 startResponse;
2141 int i;
2142 for (i = 0; i < num; i++) {
2143 p.writeInt32(p_cur[i].cid);
2144 p.writeInt32(p_cur[i].active);
2145 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002146 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002147 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002148 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002149 p_cur[i].cid,
2150 (p_cur[i].active==0)?"down":"up",
2151 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002152 (char*)p_cur[i].address);
2153 }
2154 removeLastChar;
2155 closeResponse;
2156
2157 return 0;
2158}
2159
Etan Cohend3652192014-06-20 08:28:44 -07002160static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2161{
2162 if (response == NULL && responselen != 0) {
2163 RLOGE("invalid response: NULL");
2164 return RIL_ERRNO_INVALID_RESPONSE;
2165 }
2166
2167 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2168 RLOGE("invalid response length %d expected multiple of %d",
2169 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2170 return RIL_ERRNO_INVALID_RESPONSE;
2171 }
2172
2173 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2174 p.writeInt32(num);
2175
2176 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2177 startResponse;
2178 int i;
2179 for (i = 0; i < num; i++) {
2180 p.writeInt32((int)p_cur[i].status);
2181 p.writeInt32(p_cur[i].suggestedRetryTime);
2182 p.writeInt32(p_cur[i].cid);
2183 p.writeInt32(p_cur[i].active);
2184 writeStringToParcel(p, p_cur[i].type);
2185 writeStringToParcel(p, p_cur[i].ifname);
2186 writeStringToParcel(p, p_cur[i].addresses);
2187 writeStringToParcel(p, p_cur[i].dnses);
2188 writeStringToParcel(p, p_cur[i].gateways);
2189 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2190 p_cur[i].status,
2191 p_cur[i].suggestedRetryTime,
2192 p_cur[i].cid,
2193 (p_cur[i].active==0)?"down":"up",
2194 (char*)p_cur[i].type,
2195 (char*)p_cur[i].ifname,
2196 (char*)p_cur[i].addresses,
2197 (char*)p_cur[i].dnses,
2198 (char*)p_cur[i].gateways);
2199 }
2200 removeLastChar;
2201 closeResponse;
2202
2203 return 0;
2204}
2205
Wink Saville43808972011-01-13 17:39:51 -08002206static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2207{
2208 // Write version
2209 p.writeInt32(s_callbacks.version);
2210
2211 if (s_callbacks.version < 5) {
Wink Savillec0114b32011-02-18 10:14:07 -08002212 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002213 } else {
2214 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002215 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002216 return RIL_ERRNO_INVALID_RESPONSE;
2217 }
2218
Etan Cohend3652192014-06-20 08:28:44 -07002219 // Support v6 or v9 with new rils
2220 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2221 return responseDataCallListV6(p, response, responselen);
2222 }
2223
2224 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002225 RLOGE("invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002226 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002227 return RIL_ERRNO_INVALID_RESPONSE;
2228 }
2229
Etan Cohend3652192014-06-20 08:28:44 -07002230 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002231 p.writeInt32(num);
2232
Etan Cohend3652192014-06-20 08:28:44 -07002233 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002234 startResponse;
2235 int i;
2236 for (i = 0; i < num; i++) {
2237 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002238 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002239 p.writeInt32(p_cur[i].cid);
2240 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002241 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002242 writeStringToParcel(p, p_cur[i].ifname);
2243 writeStringToParcel(p, p_cur[i].addresses);
2244 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002245 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002246 writeStringToParcel(p, p_cur[i].pcscf);
2247 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002248 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002249 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002250 p_cur[i].cid,
2251 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002252 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002253 (char*)p_cur[i].ifname,
2254 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002255 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002256 (char*)p_cur[i].gateways,
2257 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002258 }
2259 removeLastChar;
2260 closeResponse;
2261 }
2262
2263 return 0;
2264}
2265
2266static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2267{
2268 if (s_callbacks.version < 5) {
2269 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2270 } else {
2271 return responseDataCallList(p, response, responselen);
2272 }
2273}
2274
Wink Savillef4c4d362009-04-02 01:37:03 -07002275static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002276 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002277 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002278 return RIL_ERRNO_INVALID_RESPONSE;
2279 }
2280
2281 // The java code reads -1 size as null byte array
2282 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002283 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002284 } else {
2285 p.writeInt32(responselen);
2286 p.write(response, responselen);
2287 }
2288
2289 return 0;
2290}
2291
2292
Wink Savillef4c4d362009-04-02 01:37:03 -07002293static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002294 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002295 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002296 return RIL_ERRNO_INVALID_RESPONSE;
2297 }
2298
2299 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002300 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002301 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2302 return RIL_ERRNO_INVALID_RESPONSE;
2303 }
2304
2305 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2306 p.writeInt32(p_cur->sw1);
2307 p.writeInt32(p_cur->sw2);
2308 writeStringToParcel(p, p_cur->simResponse);
2309
2310 startResponse;
2311 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2312 (char*)p_cur->simResponse);
2313 closeResponse;
2314
2315
2316 return 0;
2317}
2318
Wink Savillef4c4d362009-04-02 01:37:03 -07002319static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002320 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002321
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002322 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002323 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002324 return RIL_ERRNO_INVALID_RESPONSE;
2325 }
2326
2327 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002328 RLOGE("invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002329 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2330 return RIL_ERRNO_INVALID_RESPONSE;
2331 }
2332
2333 /* number of call info's */
2334 num = responselen / sizeof(RIL_CallForwardInfo *);
2335 p.writeInt32(num);
2336
2337 startResponse;
2338 for (int i = 0 ; i < num ; i++) {
2339 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2340
2341 p.writeInt32(p_cur->status);
2342 p.writeInt32(p_cur->reason);
2343 p.writeInt32(p_cur->serviceClass);
2344 p.writeInt32(p_cur->toa);
2345 writeStringToParcel(p, p_cur->number);
2346 p.writeInt32(p_cur->timeSeconds);
2347 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2348 (p_cur->status==1)?"enable":"disable",
2349 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2350 (char*)p_cur->number,
2351 p_cur->timeSeconds);
2352 }
2353 removeLastChar;
2354 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002355
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002356 return 0;
2357}
2358
Wink Savillef4c4d362009-04-02 01:37:03 -07002359static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002360 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002361 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002362 return RIL_ERRNO_INVALID_RESPONSE;
2363 }
2364
2365 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002366 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002367 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2368 return RIL_ERRNO_INVALID_RESPONSE;
2369 }
2370
2371 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2372 p.writeInt32(p_cur->notificationType);
2373 p.writeInt32(p_cur->code);
2374 p.writeInt32(p_cur->index);
2375 p.writeInt32(p_cur->type);
2376 writeStringToParcel(p, p_cur->number);
2377
2378 startResponse;
2379 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2380 (p_cur->notificationType==0)?"mo":"mt",
2381 p_cur->code, p_cur->index, p_cur->type,
2382 (char*)p_cur->number);
2383 closeResponse;
2384
2385 return 0;
2386}
2387
Wink Saville3d54e742009-05-18 18:00:44 -07002388static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002389 int num;
2390
2391 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002392 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002393 return RIL_ERRNO_INVALID_RESPONSE;
2394 }
2395
2396 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002397 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002398 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2399 return RIL_ERRNO_INVALID_RESPONSE;
2400 }
2401
2402 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002403 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002404 num = responselen / sizeof(RIL_NeighboringCell *);
2405 p.writeInt32(num);
2406
2407 for (int i = 0 ; i < num ; i++) {
2408 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2409
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002410 p.writeInt32(p_cur->rssi);
2411 writeStringToParcel (p, p_cur->cid);
2412
2413 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2414 p_cur->cid, p_cur->rssi);
2415 }
2416 removeLastChar;
2417 closeResponse;
2418
2419 return 0;
2420}
2421
Wink Saville3d54e742009-05-18 18:00:44 -07002422/**
2423 * Marshall the signalInfoRecord into the parcel if it exists.
2424 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002425static void marshallSignalInfoRecord(Parcel &p,
2426 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002427 p.writeInt32(p_signalInfoRecord.isPresent);
2428 p.writeInt32(p_signalInfoRecord.signalType);
2429 p.writeInt32(p_signalInfoRecord.alertPitch);
2430 p.writeInt32(p_signalInfoRecord.signal);
2431}
2432
Wink Savillea592eeb2009-05-22 13:26:36 -07002433static int responseCdmaInformationRecords(Parcel &p,
2434 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002435 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002436 char* string8 = NULL;
2437 int buffer_lenght;
2438 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002439
2440 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002441 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002442 return RIL_ERRNO_INVALID_RESPONSE;
2443 }
2444
Wink Savillea592eeb2009-05-22 13:26:36 -07002445 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002446 RLOGE("invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002447 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002448 return RIL_ERRNO_INVALID_RESPONSE;
2449 }
2450
Wink Savillea592eeb2009-05-22 13:26:36 -07002451 RIL_CDMA_InformationRecords *p_cur =
2452 (RIL_CDMA_InformationRecords *) response;
2453 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002454
2455 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002456 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002457
Wink Savillea592eeb2009-05-22 13:26:36 -07002458 for (int i = 0 ; i < num ; i++) {
2459 infoRec = &p_cur->infoRec[i];
2460 p.writeInt32(infoRec->name);
2461 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002462 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002463 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2464 if (infoRec->rec.display.alpha_len >
2465 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002466 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002467 expected not more than %d\n",
2468 (int)infoRec->rec.display.alpha_len,
2469 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2470 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002471 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002472 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2473 * sizeof(char) );
2474 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2475 string8[i] = infoRec->rec.display.alpha_buf[i];
2476 }
Wink Saville43808972011-01-13 17:39:51 -08002477 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002478 writeStringToParcel(p, (const char*)string8);
2479 free(string8);
2480 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002481 break;
2482 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002483 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002484 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002485 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002486 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002487 expected not more than %d\n",
2488 (int)infoRec->rec.number.len,
2489 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2490 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002491 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002492 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2493 * sizeof(char) );
2494 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2495 string8[i] = infoRec->rec.number.buf[i];
2496 }
Wink Saville43808972011-01-13 17:39:51 -08002497 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002498 writeStringToParcel(p, (const char*)string8);
2499 free(string8);
2500 string8 = NULL;
2501 p.writeInt32(infoRec->rec.number.number_type);
2502 p.writeInt32(infoRec->rec.number.number_plan);
2503 p.writeInt32(infoRec->rec.number.pi);
2504 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002505 break;
2506 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002507 p.writeInt32(infoRec->rec.signal.isPresent);
2508 p.writeInt32(infoRec->rec.signal.signalType);
2509 p.writeInt32(infoRec->rec.signal.alertPitch);
2510 p.writeInt32(infoRec->rec.signal.signal);
2511
2512 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2513 alertPitch=%X, signal=%X, ",
2514 printBuf, (int)infoRec->rec.signal.isPresent,
2515 (int)infoRec->rec.signal.signalType,
2516 (int)infoRec->rec.signal.alertPitch,
2517 (int)infoRec->rec.signal.signal);
2518 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002519 break;
2520 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002521 if (infoRec->rec.redir.redirectingNumber.len >
2522 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002523 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002524 expected not more than %d\n",
2525 (int)infoRec->rec.redir.redirectingNumber.len,
2526 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2527 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002528 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002529 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2530 .len + 1) * sizeof(char) );
2531 for (int i = 0;
2532 i < infoRec->rec.redir.redirectingNumber.len;
2533 i++) {
2534 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2535 }
Wink Saville43808972011-01-13 17:39:51 -08002536 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002537 writeStringToParcel(p, (const char*)string8);
2538 free(string8);
2539 string8 = NULL;
2540 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2541 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2542 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2543 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2544 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002545 break;
2546 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002547 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2548 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2549 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2550 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2551
2552 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2553 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2554 lineCtrlPowerDenial=%d, ", printBuf,
2555 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2556 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2557 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2558 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2559 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002560 break;
2561 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002562 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002563
Wink Savillea592eeb2009-05-22 13:26:36 -07002564 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2565 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002566 break;
2567 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002568 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2569 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2570
2571 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2572 infoRec->rec.audioCtrl.upLink,
2573 infoRec->rec.audioCtrl.downLink);
2574 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002575 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002576 case RIL_CDMA_T53_RELEASE_INFO_REC:
2577 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002578 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002579 return RIL_ERRNO_INVALID_RESPONSE;
2580 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002581 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002582 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002583 }
2584 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002585 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002586
Wink Savillea592eeb2009-05-22 13:26:36 -07002587 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002588}
2589
Wink Savillea592eeb2009-05-22 13:26:36 -07002590static int responseRilSignalStrength(Parcel &p,
2591 void *response, size_t responselen) {
2592 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002593 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002594 return RIL_ERRNO_INVALID_RESPONSE;
2595 }
2596
Wink Savillec0114b32011-02-18 10:14:07 -08002597 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002598 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002599
Wink Saville3d54e742009-05-18 18:00:44 -07002600 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2601 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2602 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2603 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2604 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2605 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2606 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002607 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002608 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002609 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002610 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002611 if (s_callbacks.version <= 6) {
2612 // signalStrength: -1 -> 99
2613 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2614 p_cur->LTE_SignalStrength.signalStrength = 99;
2615 }
2616 // rsrp: -1 -> INT_MAX all other negative value to positive.
2617 // So remap here
2618 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2619 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2620 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2621 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2622 }
2623 // rsrq: -1 -> INT_MAX
2624 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2625 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2626 }
2627 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002628
Wink Saville18e4ab12013-04-07 17:31:04 -07002629 // cqi: -1 -> INT_MAX
2630 if (p_cur->LTE_SignalStrength.cqi == -1) {
2631 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2632 }
2633 }
2634 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002635 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2636 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2637 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2638 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002639 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2640 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2641 } else {
2642 p.writeInt32(INT_MAX);
2643 }
Wink Savillec0114b32011-02-18 10:14:07 -08002644 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002645 p.writeInt32(99);
2646 p.writeInt32(INT_MAX);
2647 p.writeInt32(INT_MAX);
2648 p.writeInt32(INT_MAX);
2649 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002650 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002651 }
johnwangfdf825f2009-05-22 15:50:34 -07002652
2653 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002654 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002655 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2656 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2657 EVDO_SS.signalNoiseRatio=%d,\
2658 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002659 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002660 printBuf,
2661 p_cur->GW_SignalStrength.signalStrength,
2662 p_cur->GW_SignalStrength.bitErrorRate,
2663 p_cur->CDMA_SignalStrength.dbm,
2664 p_cur->CDMA_SignalStrength.ecio,
2665 p_cur->EVDO_SignalStrength.dbm,
2666 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002667 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2668 p_cur->LTE_SignalStrength.signalStrength,
2669 p_cur->LTE_SignalStrength.rsrp,
2670 p_cur->LTE_SignalStrength.rsrq,
2671 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002672 p_cur->LTE_SignalStrength.cqi,
2673 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002674 closeResponse;
2675
Wink Saville3d54e742009-05-18 18:00:44 -07002676 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002677 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002678 return RIL_ERRNO_INVALID_RESPONSE;
2679 }
2680
Wink Saville3d54e742009-05-18 18:00:44 -07002681 return 0;
2682}
2683
2684static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2685 if ((response == NULL) || (responselen == 0)) {
2686 return responseVoid(p, response, responselen);
2687 } else {
2688 return responseCdmaSignalInfoRecord(p, response, responselen);
2689 }
2690}
2691
2692static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2693 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002694 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002695 return RIL_ERRNO_INVALID_RESPONSE;
2696 }
2697
2698 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002699 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002700 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2701 return RIL_ERRNO_INVALID_RESPONSE;
2702 }
2703
2704 startResponse;
2705
2706 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2707 marshallSignalInfoRecord(p, *p_cur);
2708
2709 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2710 signal=%d]",
2711 printBuf,
2712 p_cur->isPresent,
2713 p_cur->signalType,
2714 p_cur->alertPitch,
2715 p_cur->signal);
2716
2717 closeResponse;
2718 return 0;
2719}
2720
Wink Savillea592eeb2009-05-22 13:26:36 -07002721static int responseCdmaCallWaiting(Parcel &p, void *response,
2722 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002723 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002724 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002725 return RIL_ERRNO_INVALID_RESPONSE;
2726 }
2727
Wink Savillec0114b32011-02-18 10:14:07 -08002728 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002729 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002730 }
2731
2732 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2733
2734 writeStringToParcel(p, p_cur->number);
2735 p.writeInt32(p_cur->numberPresentation);
2736 writeStringToParcel(p, p_cur->name);
2737 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2738
2739 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2740 p.writeInt32(p_cur->number_type);
2741 p.writeInt32(p_cur->number_plan);
2742 } else {
2743 p.writeInt32(0);
2744 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002745 }
2746
2747 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002748 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2749 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002750 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002751 printBuf,
2752 p_cur->number,
2753 p_cur->numberPresentation,
2754 p_cur->name,
2755 p_cur->signalInfoRecord.isPresent,
2756 p_cur->signalInfoRecord.signalType,
2757 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002758 p_cur->signalInfoRecord.signal,
2759 p_cur->number_type,
2760 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002761 closeResponse;
2762
2763 return 0;
2764}
2765
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002766static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2767 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002768 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002769 return RIL_ERRNO_INVALID_RESPONSE;
2770 }
2771
2772 startResponse;
2773 if (s_callbacks.version == 7) {
2774 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2775 p.writeInt32(p_cur->result);
2776 p.writeInt32(p_cur->ef_id);
2777 writeStringToParcel(p, p_cur->aid);
2778
2779 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2780 printBuf,
2781 p_cur->result,
2782 p_cur->ef_id,
2783 p_cur->aid);
2784 } else {
2785 int *p_cur = ((int *) response);
2786 p.writeInt32(p_cur[0]);
2787 p.writeInt32(p_cur[1]);
2788 writeStringToParcel(p, NULL);
2789
2790 appendPrintBuf("%sresult=%d, ef_id=%d",
2791 printBuf,
2792 p_cur[0],
2793 p_cur[1]);
2794 }
2795 closeResponse;
2796
2797 return 0;
2798}
2799
Wink Saville8a9e0212013-04-09 12:11:38 -07002800static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2801{
2802 if (response == NULL && responselen != 0) {
2803 RLOGE("invalid response: NULL");
2804 return RIL_ERRNO_INVALID_RESPONSE;
2805 }
2806
2807 if (responselen % sizeof(RIL_CellInfo) != 0) {
2808 RLOGE("invalid response length %d expected multiple of %d",
2809 (int)responselen, (int)sizeof(RIL_CellInfo));
2810 return RIL_ERRNO_INVALID_RESPONSE;
2811 }
2812
2813 int num = responselen / sizeof(RIL_CellInfo);
2814 p.writeInt32(num);
2815
2816 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2817 startResponse;
2818 int i;
2819 for (i = 0; i < num; i++) {
2820 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2821 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2822 p.writeInt32((int)p_cur->cellInfoType);
2823 p.writeInt32(p_cur->registered);
2824 p.writeInt32(p_cur->timeStampType);
2825 p.writeInt64(p_cur->timeStamp);
2826 switch(p_cur->cellInfoType) {
2827 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07002828 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002829 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2830 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2831 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07002832 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2833 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002834 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2835 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2836
2837 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2838 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2839 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2840 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07002841 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2842 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2843 break;
2844 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07002845 case RIL_CELL_INFO_TYPE_WCDMA: {
2846 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2847 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2848 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2849 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2850 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2851 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2852 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2853 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2854 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2855
2856 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2857 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2858 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2859 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2860 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2861 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2862 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2863 break;
2864 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002865 case RIL_CELL_INFO_TYPE_CDMA: {
2866 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2867 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2868 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2869 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2870 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2871 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2872
2873 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2874 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2875 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2876 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2877 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2878
2879 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2880 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2881 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2882 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2883 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2884 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2885
2886 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2887 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2888 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2889 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2890 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2891 break;
2892 }
2893 case RIL_CELL_INFO_TYPE_LTE: {
2894 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2895 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2896 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2897 p_cur->CellInfo.lte.cellIdentityLte.ci,
2898 p_cur->CellInfo.lte.cellIdentityLte.pci,
2899 p_cur->CellInfo.lte.cellIdentityLte.tac);
2900
2901 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2902 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2903 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2904 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2905 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2906
2907 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2908 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2909 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2910 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2911 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2912 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2913 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2914 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2915 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2916 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2917 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2918 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2919 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2920 break;
2921 }
Etan Cohend3652192014-06-20 08:28:44 -07002922 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
2923 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
2924 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
2925 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
2926 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
2927 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
2928 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
2929 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
2930 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
2931
2932 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
2933 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
2934 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
2935 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
2936 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
2937 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
2938 break;
2939 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002940 }
2941 p_cur += 1;
2942 }
2943 removeLastChar;
2944 closeResponse;
2945
2946 return 0;
2947}
2948
Etan Cohend3652192014-06-20 08:28:44 -07002949static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
2950{
2951 if (response == NULL && responselen != 0) {
2952 RLOGE("invalid response: NULL");
2953 return RIL_ERRNO_INVALID_RESPONSE;
2954 }
2955
2956 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
2957 RLOGE("invalid response length %d expected multiple of %d",
2958 (int)responselen, (int)sizeof(RIL_HardwareConfig));
2959 return RIL_ERRNO_INVALID_RESPONSE;
2960 }
2961
2962 int num = responselen / sizeof(RIL_HardwareConfig);
2963 int i;
2964 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
2965
2966 p.writeInt32(num);
2967
2968 startResponse;
2969 for (i = 0; i < num; i++) {
2970 switch (p_cur[i].type) {
2971 case RIL_HARDWARE_CONFIG_MODEM: {
2972 writeStringToParcel(p, p_cur[i].uuid);
2973 p.writeInt32((int)p_cur[i].state);
2974 p.writeInt32(p_cur[i].cfg.modem.rat);
2975 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
2976 p.writeInt32(p_cur[i].cfg.modem.maxData);
2977 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
2978
2979 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
2980 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
2981 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
2982 break;
2983 }
2984 case RIL_HARDWARE_CONFIG_SIM: {
2985 writeStringToParcel(p, p_cur[i].uuid);
2986 p.writeInt32((int)p_cur[i].state);
2987 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
2988
2989 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
2990 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
2991 break;
2992 }
2993 }
2994 }
2995 removeLastChar;
2996 closeResponse;
2997 return 0;
2998}
2999
Wink Saville3d54e742009-05-18 18:00:44 -07003000static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003001 int ret;
3002 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3003 /* trigger event loop to wakeup. No reason to do this,
3004 * if we're in the event loop thread */
3005 do {
3006 ret = write (s_fdWakeupWrite, " ", 1);
3007 } while (ret < 0 && errno == EINTR);
3008 }
3009}
3010
Wink Saville3d54e742009-05-18 18:00:44 -07003011static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003012 ril_event_add(ev);
3013 triggerEvLoop();
3014}
3015
Wink Savillefd729372011-02-22 16:19:39 -08003016static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3017 p.writeInt32(num_apps);
3018 startResponse;
3019 for (int i = 0; i < num_apps; i++) {
3020 p.writeInt32(appStatus[i].app_type);
3021 p.writeInt32(appStatus[i].app_state);
3022 p.writeInt32(appStatus[i].perso_substate);
3023 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3024 writeStringToParcel(p, (const char*)
3025 (appStatus[i].app_label_ptr));
3026 p.writeInt32(appStatus[i].pin1_replaced);
3027 p.writeInt32(appStatus[i].pin1);
3028 p.writeInt32(appStatus[i].pin2);
3029 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3030 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3031 printBuf,
3032 appStatus[i].app_type,
3033 appStatus[i].app_state,
3034 appStatus[i].perso_substate,
3035 appStatus[i].aid_ptr,
3036 appStatus[i].app_label_ptr,
3037 appStatus[i].pin1_replaced,
3038 appStatus[i].pin1,
3039 appStatus[i].pin2);
3040 }
3041 closeResponse;
3042}
3043
Wink Savillef4c4d362009-04-02 01:37:03 -07003044static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3045 int i;
3046
3047 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003048 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003049 return RIL_ERRNO_INVALID_RESPONSE;
3050 }
3051
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003052 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003053 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003054
Wink Savillefd729372011-02-22 16:19:39 -08003055 p.writeInt32(p_cur->card_state);
3056 p.writeInt32(p_cur->universal_pin_state);
3057 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3058 p.writeInt32(p_cur->cdma_subscription_app_index);
3059 p.writeInt32(p_cur->ims_subscription_app_index);
3060
3061 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003062 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003063 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3064
3065 p.writeInt32(p_cur->card_state);
3066 p.writeInt32(p_cur->universal_pin_state);
3067 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3068 p.writeInt32(p_cur->cdma_subscription_app_index);
3069 p.writeInt32(-1);
3070
3071 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003072 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003073 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003074 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003075 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003076
3077 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003078}
Wink Savillef4c4d362009-04-02 01:37:03 -07003079
Wink Savillea592eeb2009-05-22 13:26:36 -07003080static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3081 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003082 p.writeInt32(num);
3083
Wink Savillef4c4d362009-04-02 01:37:03 -07003084 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003085 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3086 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3087 for (int i = 0; i < num; i++) {
3088 p.writeInt32(p_cur[i]->fromServiceId);
3089 p.writeInt32(p_cur[i]->toServiceId);
3090 p.writeInt32(p_cur[i]->fromCodeScheme);
3091 p.writeInt32(p_cur[i]->toCodeScheme);
3092 p.writeInt32(p_cur[i]->selected);
3093
3094 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3095 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3096 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3097 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3098 p_cur[i]->selected);
3099 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003100 closeResponse;
3101
3102 return 0;
3103}
3104
Wink Savillea592eeb2009-05-22 13:26:36 -07003105static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3106 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3107 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003108
Wink Savillea592eeb2009-05-22 13:26:36 -07003109 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3110 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003111
3112 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003113 for (int i = 0 ; i < num ; i++ ) {
3114 p.writeInt32(p_cur[i]->service_category);
3115 p.writeInt32(p_cur[i]->language);
3116 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003117
Wink Savillea592eeb2009-05-22 13:26:36 -07003118 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3119 selected =%d], ",
3120 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3121 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003122 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003123 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003124
Wink Savillef4c4d362009-04-02 01:37:03 -07003125 return 0;
3126}
3127
3128static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3129 int num;
3130 int digitCount;
3131 int digitLimit;
3132 uint8_t uct;
3133 void* dest;
3134
Wink Saville8eb2a122012-11-19 16:05:13 -08003135 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003136
Wink Savillef4c4d362009-04-02 01:37:03 -07003137 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003138 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003139 return RIL_ERRNO_INVALID_RESPONSE;
3140 }
3141
Wink Savillef5903df2009-04-24 11:54:14 -07003142 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003143 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003144 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003145 return RIL_ERRNO_INVALID_RESPONSE;
3146 }
3147
3148 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3149 p.writeInt32(p_cur->uTeleserviceID);
3150 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3151 p.writeInt32(p_cur->uServicecategory);
3152 p.writeInt32(p_cur->sAddress.digit_mode);
3153 p.writeInt32(p_cur->sAddress.number_mode);
3154 p.writeInt32(p_cur->sAddress.number_type);
3155 p.writeInt32(p_cur->sAddress.number_plan);
3156 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3157 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3158 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3159 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3160 }
3161
3162 p.writeInt32(p_cur->sSubAddress.subaddressType);
3163 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3164 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3165 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3166 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3167 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3168 }
3169
3170 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3171 p.writeInt32(p_cur->uBearerDataLen);
3172 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3173 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3174 }
3175
3176 startResponse;
3177 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003178 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003179 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3180 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3181 closeResponse;
3182
3183 return 0;
3184}
3185
Wink Savillec29360a2014-07-13 05:17:28 -07003186static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3187{
3188 int num = responselen / sizeof(RIL_DcRtInfo);
3189 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3190 RLOGE("invalid response length %d expected multiple of %d",
3191 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3192 return RIL_ERRNO_INVALID_RESPONSE;
3193 }
3194
3195 startResponse;
3196 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3197 p.writeInt64(pDcRtInfo->time);
3198 p.writeInt32(pDcRtInfo->powerState);
3199 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3200 pDcRtInfo->time,
3201 pDcRtInfo->powerState);
3202 closeResponse;
3203
3204 return 0;
3205}
3206
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003207/**
3208 * A write on the wakeup fd is done just to pop us out of select()
3209 * We empty the buffer here and then ril_event will reset the timers on the
3210 * way back down
3211 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003212static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003213 char buff[16];
3214 int ret;
3215
Wink Saville8eb2a122012-11-19 16:05:13 -08003216 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003217
3218 /* empty our wakeup socket out */
3219 do {
3220 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003221 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003222}
3223
Etan Cohend3652192014-06-20 08:28:44 -07003224static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003225 int ret;
3226 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003227 /* Hook for current context
3228 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3229 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3230 /* pendingRequestsHook refer to &s_pendingRequests */
3231 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003232
Etan Cohend3652192014-06-20 08:28:44 -07003233#if (SIM_COUNT >= 2)
3234 if (socket_id == RIL_SOCKET_2) {
3235 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3236 pendingRequestsHook = &s_pendingRequests_socket2;
3237 }
3238#if (SIM_COUNT >= 3)
3239 else if (socket_id == RIL_SOCKET_3) {
3240 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3241 pendingRequestsHook = &s_pendingRequests_socket3;
3242 }
3243#endif
3244#if (SIM_COUNT >= 4)
3245 else if (socket_id == RIL_SOCKET_4) {
3246 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3247 pendingRequestsHook = &s_pendingRequests_socket4;
3248 }
3249#endif
3250#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003251 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003252 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003253 assert (ret == 0);
3254
Etan Cohend3652192014-06-20 08:28:44 -07003255 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003256
Etan Cohend3652192014-06-20 08:28:44 -07003257 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003258 ; p_cur != NULL
3259 ; p_cur = p_cur->p_next
3260 ) {
3261 p_cur->cancelled = 1;
3262 }
3263
Etan Cohend3652192014-06-20 08:28:44 -07003264 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003265 assert (ret == 0);
3266}
3267
Wink Savillef4c4d362009-04-02 01:37:03 -07003268static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003269 RecordStream *p_rs;
3270 void *p_record;
3271 size_t recordlen;
3272 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003273 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003274
Etan Cohend3652192014-06-20 08:28:44 -07003275 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003276
Etan Cohend3652192014-06-20 08:28:44 -07003277 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003278
3279 for (;;) {
3280 /* loop until EAGAIN/EINTR, end of stream, or other error */
3281 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3282
3283 if (ret == 0 && p_record == NULL) {
3284 /* end-of-stream */
3285 break;
3286 } else if (ret < 0) {
3287 break;
3288 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003289 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003290 }
3291 }
3292
3293 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3294 /* fatal error or end-of-stream */
3295 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003296 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003297 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003298 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003299 }
Wink Saville7f856802009-06-09 10:23:37 -07003300
Etan Cohend3652192014-06-20 08:28:44 -07003301 close(fd);
3302 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003303
Etan Cohend3652192014-06-20 08:28:44 -07003304 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003305
3306 record_stream_free(p_rs);
3307
3308 /* start listening for new connections again */
3309 rilEventAddWakeup(&s_listen_event);
3310
Etan Cohend3652192014-06-20 08:28:44 -07003311 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003312 }
3313}
3314
3315
Etan Cohend3652192014-06-20 08:28:44 -07003316static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003317 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003318 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003319 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3320 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003321
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003322 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003323 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3324 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003325
3326 // Send last NITZ time data, in case it was missed
3327 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003328 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003329
3330 free(s_lastNITZTimeData);
3331 s_lastNITZTimeData = NULL;
3332 }
3333
3334 // Get version string
3335 if (s_callbacks.getVersion != NULL) {
3336 const char *version;
3337 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003338 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003339
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003340 property_set(PROPERTY_RIL_IMPL, version);
3341 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003342 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003343 property_set(PROPERTY_RIL_IMPL, "unavailable");
3344 }
3345
3346}
3347
Wink Savillef4c4d362009-04-02 01:37:03 -07003348static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003349 int ret;
3350 int err;
3351 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003352 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003353 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003354 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003355
3356 struct sockaddr_un peeraddr;
3357 socklen_t socklen = sizeof (peeraddr);
3358
3359 struct ucred creds;
3360 socklen_t szCreds = sizeof(creds);
3361
3362 struct passwd *pwd = NULL;
3363
Etan Cohend3652192014-06-20 08:28:44 -07003364 assert (*p_info->fdCommand < 0);
3365 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003366
Etan Cohend3652192014-06-20 08:28:44 -07003367 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003368
Etan Cohend3652192014-06-20 08:28:44 -07003369 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003370 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003371 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003372 rilEventAddWakeup(p_info->listen_event);
3373 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003374 }
3375
3376 /* check the credential of the other side and only accept socket from
3377 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003378 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003379 errno = 0;
3380 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003381
Etan Cohend3652192014-06-20 08:28:44 -07003382 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003383
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003384 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003385 errno = 0;
3386 pwd = getpwuid(creds.uid);
3387 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003388 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003389 is_phone_socket = 1;
3390 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003391 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003392 }
3393 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003394 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003395 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003396 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003397 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003398 }
3399
Etan Cohend3652192014-06-20 08:28:44 -07003400 if (!is_phone_socket) {
3401 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003402
Etan Cohend3652192014-06-20 08:28:44 -07003403 close(fdCommand);
3404 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003405
Etan Cohend3652192014-06-20 08:28:44 -07003406 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003407
3408 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003409 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003410
3411 return;
3412 }
3413
Etan Cohend3652192014-06-20 08:28:44 -07003414 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003415
3416 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003417 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003418 }
3419
Etan Cohend3652192014-06-20 08:28:44 -07003420 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003421
Etan Cohend3652192014-06-20 08:28:44 -07003422 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003423
Etan Cohend3652192014-06-20 08:28:44 -07003424 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003425
Etan Cohend3652192014-06-20 08:28:44 -07003426 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003427
Etan Cohend3652192014-06-20 08:28:44 -07003428 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3429 p_info->processCommandsCallback, p_info);
3430
3431 rilEventAddWakeup (p_info->commands_event);
3432
3433 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003434}
3435
3436static void freeDebugCallbackArgs(int number, char **args) {
3437 for (int i = 0; i < number; i++) {
3438 if (args[i] != NULL) {
3439 free(args[i]);
3440 }
3441 }
3442 free(args);
3443}
3444
Wink Savillef4c4d362009-04-02 01:37:03 -07003445static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003446 int acceptFD, option;
3447 struct sockaddr_un peeraddr;
3448 socklen_t socklen = sizeof (peeraddr);
3449 int data;
3450 unsigned int qxdm_data[6];
3451 const char *deactData[1] = {"1"};
3452 char *actData[1];
3453 RIL_Dial dialData;
3454 int hangupData[1] = {1};
3455 int number;
3456 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003457 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3458 int sim_id = 0;
3459
3460 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003461
3462 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3463
3464 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003465 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003466 return;
3467 }
3468
3469 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003470 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003471 return;
3472 }
3473 args = (char **) malloc(sizeof(char*) * number);
3474
3475 for (int i = 0; i < number; i++) {
3476 int len;
3477 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003478 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003479 freeDebugCallbackArgs(i, args);
3480 return;
3481 }
3482 // +1 for null-term
3483 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003484 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003485 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003486 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003487 freeDebugCallbackArgs(i, args);
3488 return;
3489 }
3490 char * buf = args[i];
3491 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003492 if ((i+1) == number) {
3493 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3494 sim_id = atoi(args[i]);
3495 switch (sim_id) {
3496 case 0:
3497 socket_id = RIL_SOCKET_1;
3498 break;
3499 #if (SIM_COUNT >= 2)
3500 case 1:
3501 socket_id = RIL_SOCKET_2;
3502 break;
3503 #endif
3504 #if (SIM_COUNT >= 3)
3505 case 2:
3506 socket_id = RIL_SOCKET_3;
3507 break;
3508 #endif
3509 #if (SIM_COUNT >= 4)
3510 case 3:
3511 socket_id = RIL_SOCKET_4;
3512 break;
3513 #endif
3514 default:
3515 socket_id = RIL_SOCKET_1;
3516 break;
3517 }
3518 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003519 }
3520
3521 switch (atoi(args[0])) {
3522 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003523 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003524 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003525 break;
3526 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003527 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003528 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003529 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003530 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003531 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3532 close(s_ril_param_socket.fdCommand);
3533 s_ril_param_socket.fdCommand = -1;
3534 }
3535 #if (SIM_COUNT == 2)
3536 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3537 close(s_ril_param_socket2.fdCommand);
3538 s_ril_param_socket2.fdCommand = -1;
3539 }
3540 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003541 break;
3542 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003543 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003544 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003545 break;
3546 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003547 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003548 qxdm_data[0] = 65536; // head.func_tag
3549 qxdm_data[1] = 16; // head.len
3550 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3551 qxdm_data[3] = 32; // log_file_size: 32megabytes
3552 qxdm_data[4] = 0; // log_mask
3553 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003554 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003555 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003556 break;
3557 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003558 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003559 qxdm_data[0] = 65536;
3560 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003561 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003562 qxdm_data[3] = 32;
3563 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003564 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003565 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003566 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003567 break;
3568 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003569 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003570 data = 1;
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 sleep(2);
3573 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003574 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003575 break;
3576 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003577 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003578 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003579 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003580 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003581 break;
3582 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003583 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003584 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003585 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003586 break;
3587 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003588 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003589 dialData.clir = 0;
3590 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003591 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003592 break;
3593 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003594 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003595 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003596 break;
3597 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003598 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003599 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003600 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003601 break;
3602 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003603 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003604 break;
3605 }
3606 freeDebugCallbackArgs(number, args);
3607 close(acceptFD);
3608}
3609
3610
Wink Savillef4c4d362009-04-02 01:37:03 -07003611static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003612 UserCallbackInfo *p_info;
3613
3614 p_info = (UserCallbackInfo *)param;
3615
3616 p_info->p_callback(p_info->userParam);
3617
3618
3619 // FIXME generalize this...there should be a cancel mechanism
3620 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3621 s_last_wake_timeout_info = NULL;
3622 }
3623
3624 free(p_info);
3625}
3626
3627
3628static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003629eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003630 int ret;
3631 int filedes[2];
3632
3633 ril_event_init();
3634
3635 pthread_mutex_lock(&s_startupMutex);
3636
3637 s_started = 1;
3638 pthread_cond_broadcast(&s_startupCond);
3639
3640 pthread_mutex_unlock(&s_startupMutex);
3641
3642 ret = pipe(filedes);
3643
3644 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003645 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003646 return NULL;
3647 }
3648
3649 s_fdWakeupRead = filedes[0];
3650 s_fdWakeupWrite = filedes[1];
3651
3652 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3653
3654 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3655 processWakeupCallback, NULL);
3656
3657 rilEventAddWakeup (&s_wakeupfd_event);
3658
3659 // Only returns on error
3660 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003661 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003662 // kill self to restart on error
3663 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003664
3665 return NULL;
3666}
3667
Wink Saville7f856802009-06-09 10:23:37 -07003668extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003669RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003670 /* spin up eventLoop thread and wait for it to get started */
3671 s_started = 0;
3672 pthread_mutex_lock(&s_startupMutex);
3673
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003674 pthread_attr_t attr;
3675 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003676 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003677
Elliott Hughesfd81e712014-01-06 12:46:02 -08003678 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3679 if (result != 0) {
3680 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003681 goto done;
3682 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003683
3684 while (s_started == 0) {
3685 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3686 }
3687
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003688done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003689 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003690}
3691
3692// Used for testing purpose only.
3693extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3694 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3695}
3696
Etan Cohend3652192014-06-20 08:28:44 -07003697static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3698 int fdListen = -1;
3699 int ret;
3700 char socket_name[10];
3701
3702 memset(socket_name, 0, sizeof(char)*10);
3703
3704 switch(socket_id) {
3705 case RIL_SOCKET_1:
3706 strncpy(socket_name, RIL_getRilSocketName(), 9);
3707 break;
3708 #if (SIM_COUNT >= 2)
3709 case RIL_SOCKET_2:
3710 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3711 break;
3712 #endif
3713 #if (SIM_COUNT >= 3)
3714 case RIL_SOCKET_3:
3715 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3716 break;
3717 #endif
3718 #if (SIM_COUNT >= 4)
3719 case RIL_SOCKET_4:
3720 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3721 break;
3722 #endif
3723 default:
3724 RLOGE("Socket id is wrong!!");
3725 return;
3726 }
3727
3728 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3729
3730 fdListen = android_get_control_socket(socket_name);
3731 if (fdListen < 0) {
3732 RLOGE("Failed to get socket %s", socket_name);
3733 exit(-1);
3734 }
3735
3736 ret = listen(fdListen, 4);
3737
3738 if (ret < 0) {
3739 RLOGE("Failed to listen on control socket '%d': %s",
3740 fdListen, strerror(errno));
3741 exit(-1);
3742 }
3743 socket_listen_p->fdListen = fdListen;
3744
3745 /* note: non-persistent so we can accept only one connection at a time */
3746 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3747 listenCallback, socket_listen_p);
3748
3749 rilEventAddWakeup (socket_listen_p->listen_event);
3750}
3751
Wink Saville7f856802009-06-09 10:23:37 -07003752extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003753RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003754 int ret;
3755 int flags;
3756
Etan Cohend3652192014-06-20 08:28:44 -07003757 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3758
Wink Saville43808972011-01-13 17:39:51 -08003759 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003760 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003761 return;
3762 }
Wink Saville43808972011-01-13 17:39:51 -08003763 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003764 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003765 callbacks->version, RIL_VERSION_MIN);
3766 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07003767 }
Wink Saville43808972011-01-13 17:39:51 -08003768 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003769 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003770 callbacks->version, RIL_VERSION);
3771 return;
3772 }
Wink Saville8eb2a122012-11-19 16:05:13 -08003773 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003774
3775 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003776 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003777 "Subsequent call ignored");
3778 return;
3779 }
3780
3781 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3782
Etan Cohend3652192014-06-20 08:28:44 -07003783 /* Initialize socket1 parameters */
3784 s_ril_param_socket = {
3785 RIL_SOCKET_1, /* socket_id */
3786 -1, /* fdListen */
3787 -1, /* fdCommand */
3788 PHONE_PROCESS, /* processName */
3789 &s_commands_event, /* commands_event */
3790 &s_listen_event, /* listen_event */
3791 processCommandsCallback, /* processCommandsCallback */
3792 NULL /* p_rs */
3793 };
3794
3795#if (SIM_COUNT >= 2)
3796 s_ril_param_socket2 = {
3797 RIL_SOCKET_2, /* socket_id */
3798 -1, /* fdListen */
3799 -1, /* fdCommand */
3800 PHONE_PROCESS, /* processName */
3801 &s_commands_event_socket2, /* commands_event */
3802 &s_listen_event_socket2, /* listen_event */
3803 processCommandsCallback, /* processCommandsCallback */
3804 NULL /* p_rs */
3805 };
3806#endif
3807
3808#if (SIM_COUNT >= 3)
3809 s_ril_param_socket3 = {
3810 RIL_SOCKET_3, /* socket_id */
3811 -1, /* fdListen */
3812 -1, /* fdCommand */
3813 PHONE_PROCESS, /* processName */
3814 &s_commands_event_socket3, /* commands_event */
3815 &s_listen_event_socket3, /* listen_event */
3816 processCommandsCallback, /* processCommandsCallback */
3817 NULL /* p_rs */
3818 };
3819#endif
3820
3821#if (SIM_COUNT >= 4)
3822 s_ril_param_socket4 = {
3823 RIL_SOCKET_4, /* socket_id */
3824 -1, /* fdListen */
3825 -1, /* fdCommand */
3826 PHONE_PROCESS, /* processName */
3827 &s_commands_event_socket4, /* commands_event */
3828 &s_listen_event_socket4, /* listen_event */
3829 processCommandsCallback, /* processCommandsCallback */
3830 NULL /* p_rs */
3831 };
3832#endif
3833
3834
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003835 s_registerCalled = 1;
3836
Etan Cohend3652192014-06-20 08:28:44 -07003837 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003838 // Little self-check
3839
Wink Savillef4c4d362009-04-02 01:37:03 -07003840 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003841 assert(i == s_commands[i].requestNumber);
3842 }
3843
Wink Savillef4c4d362009-04-02 01:37:03 -07003844 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07003845 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003846 == s_unsolResponses[i].requestNumber);
3847 }
3848
3849 // New rild impl calls RIL_startEventLoop() first
3850 // old standalone impl wants it here.
3851
3852 if (s_started == 0) {
3853 RIL_startEventLoop();
3854 }
3855
Etan Cohend3652192014-06-20 08:28:44 -07003856 // start listen socket1
3857 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003858
Etan Cohend3652192014-06-20 08:28:44 -07003859#if (SIM_COUNT >= 2)
3860 // start listen socket2
3861 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
3862#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003863
Etan Cohend3652192014-06-20 08:28:44 -07003864#if (SIM_COUNT >= 3)
3865 // start listen socket3
3866 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
3867#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003868
Etan Cohend3652192014-06-20 08:28:44 -07003869#if (SIM_COUNT >= 4)
3870 // start listen socket4
3871 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
3872#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003873
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003874
3875#if 1
3876 // start debug interface socket
3877
Etan Cohend3652192014-06-20 08:28:44 -07003878 char *inst = NULL;
3879 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
3880 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
3881 }
3882
3883 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
3884 if (inst != NULL) {
3885 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
3886 }
3887
3888 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003889 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07003890 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003891 exit(-1);
3892 }
3893
3894 ret = listen(s_fdDebug, 4);
3895
3896 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003897 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003898 s_fdDebug, strerror(errno));
3899 exit(-1);
3900 }
3901
3902 ril_event_set (&s_debug_event, s_fdDebug, true,
3903 debugCallback, NULL);
3904
3905 rilEventAddWakeup (&s_debug_event);
3906#endif
3907
3908}
3909
3910static int
Wink Savillef4c4d362009-04-02 01:37:03 -07003911checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003912 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003913 /* Hook for current context
3914 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3915 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
3916 /* pendingRequestsHook refer to &s_pendingRequests */
3917 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07003918
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003919 if (pRI == NULL) {
3920 return 0;
3921 }
3922
Etan Cohend3652192014-06-20 08:28:44 -07003923#if (SIM_COUNT >= 2)
3924 if (pRI->socket_id == RIL_SOCKET_2) {
3925 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3926 pendingRequestsHook = &s_pendingRequests_socket2;
3927 }
3928#if (SIM_COUNT >= 3)
3929 if (pRI->socket_id == RIL_SOCKET_3) {
3930 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3931 pendingRequestsHook = &s_pendingRequests_socket3;
3932 }
3933#endif
3934#if (SIM_COUNT >= 4)
3935 if (pRI->socket_id == RIL_SOCKET_4) {
3936 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3937 pendingRequestsHook = &s_pendingRequests_socket4;
3938 }
3939#endif
3940#endif
3941 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003942
Etan Cohend3652192014-06-20 08:28:44 -07003943 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07003944 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003945 ; ppCur = &((*ppCur)->p_next)
3946 ) {
3947 if (pRI == *ppCur) {
3948 ret = 1;
3949
3950 *ppCur = (*ppCur)->p_next;
3951 break;
3952 }
3953 }
3954
Etan Cohend3652192014-06-20 08:28:44 -07003955 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003956
3957 return ret;
3958}
3959
3960
3961extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003962RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003963 RequestInfo *pRI;
3964 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003965 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003966 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07003967 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003968
3969 pRI = (RequestInfo *)t;
3970
Etan Cohend3652192014-06-20 08:28:44 -07003971 socket_id = pRI->socket_id;
3972#if (SIM_COUNT >= 2)
3973 if (socket_id == RIL_SOCKET_2) {
3974 fd = s_ril_param_socket2.fdCommand;
3975 }
3976#if (SIM_COUNT >= 3)
3977 if (socket_id == RIL_SOCKET_3) {
3978 fd = s_ril_param_socket3.fdCommand;
3979 }
3980#endif
3981#if (SIM_COUNT >= 4)
3982 if (socket_id == RIL_SOCKET_4) {
3983 fd = s_ril_param_socket4.fdCommand;
3984 }
3985#endif
3986#endif
3987 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
3988
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003989 if (!checkAndDequeueRequestInfo(pRI)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003990 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003991 return;
3992 }
3993
3994 if (pRI->local > 0) {
3995 // Locally issued command...void only!
3996 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08003997 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003998
3999 goto done;
4000 }
4001
4002 appendPrintBuf("[%04d]< %s",
4003 pRI->token, requestToString(pRI->pCI->requestNumber));
4004
4005 if (pRI->cancelled == 0) {
4006 Parcel p;
4007
4008 p.writeInt32 (RESPONSE_SOLICITED);
4009 p.writeInt32 (pRI->token);
4010 errorOffset = p.dataPosition();
4011
4012 p.writeInt32 (e);
4013
johnwangb2a61842009-06-02 14:55:45 -07004014 if (response != NULL) {
4015 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004016 ret = pRI->pCI->responseFunction(p, response, responselen);
4017
4018 /* if an error occurred, rewind and mark it */
4019 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004020 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004021 p.setDataPosition(errorOffset);
4022 p.writeInt32 (ret);
4023 }
johnwangb2a61842009-06-02 14:55:45 -07004024 }
4025
4026 if (e != RIL_E_SUCCESS) {
4027 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004028 }
4029
Etan Cohend3652192014-06-20 08:28:44 -07004030 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004031 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004032 }
Etan Cohend3652192014-06-20 08:28:44 -07004033 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004034 }
4035
4036done:
4037 free(pRI);
4038}
4039
4040
4041static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004042grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004043 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4044}
4045
4046static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004047releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004048 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4049}
4050
4051/**
4052 * Timer callback to put us back to sleep before the default timeout
4053 */
4054static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004055wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004056 // We're using "param != NULL" as a cancellation mechanism
4057 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004058 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004059
4060 releaseWakeLock();
4061 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004062 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004063 }
4064}
4065
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004066static int
4067decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4068 switch (radioState) {
4069 case RADIO_STATE_SIM_NOT_READY:
4070 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4071 case RADIO_STATE_SIM_READY:
4072 return RADIO_TECH_UMTS;
4073
4074 case RADIO_STATE_RUIM_NOT_READY:
4075 case RADIO_STATE_RUIM_READY:
4076 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4077 case RADIO_STATE_NV_NOT_READY:
4078 case RADIO_STATE_NV_READY:
4079 return RADIO_TECH_1xRTT;
4080
4081 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004082 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004083 return -1;
4084 }
4085}
4086
4087static int
4088decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4089 switch (radioState) {
4090 case RADIO_STATE_SIM_NOT_READY:
4091 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4092 case RADIO_STATE_SIM_READY:
4093 case RADIO_STATE_RUIM_NOT_READY:
4094 case RADIO_STATE_RUIM_READY:
4095 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4096 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4097
4098 case RADIO_STATE_NV_NOT_READY:
4099 case RADIO_STATE_NV_READY:
4100 return CDMA_SUBSCRIPTION_SOURCE_NV;
4101
4102 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004103 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004104 return -1;
4105 }
4106}
4107
4108static int
4109decodeSimStatus (RIL_RadioState radioState) {
4110 switch (radioState) {
4111 case RADIO_STATE_SIM_NOT_READY:
4112 case RADIO_STATE_RUIM_NOT_READY:
4113 case RADIO_STATE_NV_NOT_READY:
4114 case RADIO_STATE_NV_READY:
4115 return -1;
4116 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4117 case RADIO_STATE_SIM_READY:
4118 case RADIO_STATE_RUIM_READY:
4119 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4120 return radioState;
4121 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004122 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004123 return -1;
4124 }
4125}
4126
4127static bool is3gpp2(int radioTech) {
4128 switch (radioTech) {
4129 case RADIO_TECH_IS95A:
4130 case RADIO_TECH_IS95B:
4131 case RADIO_TECH_1xRTT:
4132 case RADIO_TECH_EVDO_0:
4133 case RADIO_TECH_EVDO_A:
4134 case RADIO_TECH_EVDO_B:
4135 case RADIO_TECH_EHRPD:
4136 return true;
4137 default:
4138 return false;
4139 }
4140}
4141
4142/* If RIL sends SIM states or RUIM states, store the voice radio
4143 * technology and subscription source information so that they can be
4144 * returned when telephony framework requests them
4145 */
4146static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004147processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004148
4149 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4150 int newVoiceRadioTech;
4151 int newCdmaSubscriptionSource;
4152 int newSimStatus;
4153
4154 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4155 from Radio State and send change notifications if there has been a change */
4156 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4157 if(newVoiceRadioTech != voiceRadioTech) {
4158 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004159 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4160 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004161 }
4162 if(is3gpp2(newVoiceRadioTech)) {
4163 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4164 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4165 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004166 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4167 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004168 }
4169 }
4170 newSimStatus = decodeSimStatus(newRadioState);
4171 if(newSimStatus != simRuimStatus) {
4172 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004173 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004174 }
4175
4176 /* Send RADIO_ON to telephony */
4177 newRadioState = RADIO_STATE_ON;
4178 }
4179
4180 return newRadioState;
4181}
4182
Etan Cohend3652192014-06-20 08:28:44 -07004183
4184#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004185extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004186void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4187 size_t datalen, RIL_SOCKET_ID socket_id)
4188#else
4189extern "C"
4190void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004191 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004192#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004193{
4194 int unsolResponseIndex;
4195 int ret;
4196 int64_t timeReceived = 0;
4197 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004198 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004199 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4200
4201#if defined(ANDROID_MULTI_SIM)
4202 soc_id = socket_id;
4203#endif
4204
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004205
4206 if (s_registerCalled == 0) {
4207 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004208 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004209 return;
4210 }
Wink Saville7f856802009-06-09 10:23:37 -07004211
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004212 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4213
4214 if ((unsolResponseIndex < 0)
4215 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004216 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004217 return;
4218 }
4219
4220 // Grab a wake lock if needed for this reponse,
4221 // as we exit we'll either release it immediately
4222 // or set a timer to release it later.
4223 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4224 case WAKE_PARTIAL:
4225 grabPartialWakeLock();
4226 shouldScheduleTimeout = true;
4227 break;
4228
4229 case DONT_WAKE:
4230 default:
4231 // No wake lock is grabed so don't set timeout
4232 shouldScheduleTimeout = false;
4233 break;
4234 }
4235
4236 // Mark the time this was received, doing this
4237 // after grabing the wakelock incase getting
4238 // the elapsedRealTime might cause us to goto
4239 // sleep.
4240 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4241 timeReceived = elapsedRealtime();
4242 }
4243
4244 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4245
4246 Parcel p;
4247
4248 p.writeInt32 (RESPONSE_UNSOLICITED);
4249 p.writeInt32 (unsolResponse);
4250
4251 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004252 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004253 if (ret != 0) {
4254 // Problem with the response. Don't continue;
4255 goto error_exit;
4256 }
4257
4258 // some things get more payload
4259 switch(unsolResponse) {
4260 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004261 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004262 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004263 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004264 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004265 break;
4266
4267
4268 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4269 // Store the time that this was received so the
4270 // handler of this message can account for
4271 // the time it takes to arrive and process. In
4272 // particular the system has been known to sleep
4273 // before this message can be processed.
4274 p.writeInt64(timeReceived);
4275 break;
4276 }
4277
Etan Cohend3652192014-06-20 08:28:44 -07004278 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4279 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004280 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4281
4282 // Unfortunately, NITZ time is not poll/update like everything
4283 // else in the system. So, if the upstream client isn't connected,
4284 // keep a copy of the last NITZ response (with receive time noted
4285 // above) around so we can deliver it when it is connected
4286
4287 if (s_lastNITZTimeData != NULL) {
4288 free (s_lastNITZTimeData);
4289 s_lastNITZTimeData = NULL;
4290 }
4291
4292 s_lastNITZTimeData = malloc(p.dataSize());
4293 s_lastNITZTimeDataSize = p.dataSize();
4294 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4295 }
4296
4297 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4298 // FIXME The java code should handshake here to release wake lock
4299
4300 if (shouldScheduleTimeout) {
4301 // Cancel the previous request
4302 if (s_last_wake_timeout_info != NULL) {
4303 s_last_wake_timeout_info->userParam = (void *)1;
4304 }
4305
4306 s_last_wake_timeout_info
4307 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4308 &TIMEVAL_WAKE_TIMEOUT);
4309 }
4310
4311 // Normal exit
4312 return;
4313
4314error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004315 if (shouldScheduleTimeout) {
4316 releaseWakeLock();
4317 }
4318}
4319
Wink Saville7f856802009-06-09 10:23:37 -07004320/** FIXME generalize this if you track UserCAllbackInfo, clear it
4321 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004322*/
4323static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004324internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004325 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004326{
4327 struct timeval myRelativeTime;
4328 UserCallbackInfo *p_info;
4329
4330 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4331
Wink Saville7f856802009-06-09 10:23:37 -07004332 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004333 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004334
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004335 if (relativeTime == NULL) {
4336 /* treat null parameter as a 0 relative time */
4337 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4338 } else {
4339 /* FIXME I think event_add's tv param is really const anyway */
4340 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4341 }
4342
4343 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4344
4345 ril_timer_add(&(p_info->event), &myRelativeTime);
4346
4347 triggerEvLoop();
4348 return p_info;
4349}
4350
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004351
4352extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004353RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4354 const struct timeval *relativeTime) {
4355 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004356}
4357
4358const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004359failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004360 switch(e) {
4361 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004362 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004363 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4364 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4365 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4366 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4367 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4368 case RIL_E_CANCELLED: return "E_CANCELLED";
4369 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4370 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4371 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004372 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004373 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004374#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004375 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4376 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4377#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004378 default: return "<unknown error>";
4379 }
4380}
4381
4382const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004383radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004384 switch(s) {
4385 case RADIO_STATE_OFF: return "RADIO_OFF";
4386 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4387 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4388 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4389 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004390 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4391 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4392 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4393 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4394 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004395 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004396 default: return "<unknown state>";
4397 }
4398}
4399
4400const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004401callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402 switch(s) {
4403 case RIL_CALL_ACTIVE : return "ACTIVE";
4404 case RIL_CALL_HOLDING: return "HOLDING";
4405 case RIL_CALL_DIALING: return "DIALING";
4406 case RIL_CALL_ALERTING: return "ALERTING";
4407 case RIL_CALL_INCOMING: return "INCOMING";
4408 case RIL_CALL_WAITING: return "WAITING";
4409 default: return "<unknown state>";
4410 }
4411}
4412
4413const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004414requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004415/*
4416 cat libs/telephony/ril_commands.h \
4417 | egrep "^ *{RIL_" \
4418 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4419
4420
4421 cat libs/telephony/ril_unsol_commands.h \
4422 | egrep "^ *{RIL_" \
4423 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4424
4425*/
4426 switch(request) {
4427 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4428 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4429 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4430 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4431 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4432 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4433 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4434 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4435 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4436 case RIL_REQUEST_DIAL: return "DIAL";
4437 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4438 case RIL_REQUEST_HANGUP: return "HANGUP";
4439 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4440 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4441 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4442 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4443 case RIL_REQUEST_UDUB: return "UDUB";
4444 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4445 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004446 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4447 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004448 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4449 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4450 case RIL_REQUEST_DTMF: return "DTMF";
4451 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4452 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004453 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004454 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4455 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4456 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4457 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4458 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4459 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4460 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4461 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4462 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4463 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4464 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4465 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4466 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004467 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004468 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4469 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4470 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4471 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4472 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4473 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4474 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4475 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4476 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4477 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4478 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4479 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4480 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4481 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4482 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4483 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4484 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004485 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4486 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004487 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4488 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4489 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004490 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4491 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004492 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4493 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4494 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4495 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4496 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4497 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4498 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4499 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004500 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004501 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4502 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4503 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4504 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4505 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4506 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4507 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4508 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4509 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4510 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004511 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4512 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4513 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4514 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4515 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004516 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004517 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4518 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4519 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4520 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004521 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4522 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4523 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004524 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004525 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004526 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004527 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004528 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4529 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004530 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004531 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4532 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004533 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004534 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4535 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004536 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4537 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4538 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4539 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Etan Cohend3652192014-06-20 08:28:44 -07004540 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4541 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004542 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4543 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004544 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4545 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004546 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4547 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004548 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 -08004549 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4550 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4551 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4552 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4553 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4554 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4555 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4556 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4557 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4558 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4559 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4560 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4561 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004562 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004563 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004564 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4565 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4566 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4567 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004568 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4569 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4570 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4571 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4572 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004573 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004574 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004575 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004576 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004577 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4578 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004579 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004580 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004581 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004582 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004583 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4584 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4585 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004586 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004587 default: return "<unknown request>";
4588 }
4589}
4590
Etan Cohend3652192014-06-20 08:28:44 -07004591const char *
4592rilSocketIdToString(RIL_SOCKET_ID socket_id)
4593{
4594 switch(socket_id) {
4595 case RIL_SOCKET_1:
4596 return "RIL_SOCKET_1";
4597#if (SIM_COUNT >= 2)
4598 case RIL_SOCKET_2:
4599 return "RIL_SOCKET_2";
4600#endif
4601#if (SIM_COUNT >= 3)
4602 case RIL_SOCKET_3:
4603 return "RIL_SOCKET_3";
4604#endif
4605#if (SIM_COUNT >= 4)
4606 case RIL_SOCKET_4:
4607 return "RIL_SOCKET_4";
4608#endif
4609 default:
4610 return "not a valid RIL";
4611 }
4612}
4613
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004614} /* namespace android */