blob: 4b3e1b88be94687a415bad638bcd77a4176110ca [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
22#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070023#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080024#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070026#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070030#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <cutils/jstring.h>
32
33#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070034#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
68
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Constants for response types */
84#define RESPONSE_SOLICITED 0
85#define RESPONSE_UNSOLICITED 1
86
87/* Negative values for private RIL errno's */
88#define RIL_ERRNO_INVALID_RESPONSE -1
89
90// request, response, and unsolicited msg print macro
91#define PRINTBUF_SIZE 8096
92
93// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
108 #define appendPrintBuf(x...) sprintf(printBuf, x)
109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700136 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700141 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142} RequestInfo;
143
Wink Saville3d54e742009-05-18 18:00:44 -0700144typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Etan Cohend3652192014-06-20 08:28:44 -0700151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
185static struct ril_event s_commands_event;
186static struct ril_event s_wakeupfd_event;
187static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700188static SocketListenParam s_ril_param_socket;
189
190static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests = NULL;
193
194#if (SIM_COUNT >= 2)
195static struct ril_event s_commands_event_socket2;
196static struct ril_event s_listen_event_socket2;
197static SocketListenParam s_ril_param_socket2;
198
199static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
200static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
201static RequestInfo *s_pendingRequests_socket2 = NULL;
202#endif
203
204#if (SIM_COUNT >= 3)
205static struct ril_event s_commands_event_socket3;
206static struct ril_event s_listen_event_socket3;
207static SocketListenParam s_ril_param_socket3;
208
209static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
210static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
211static RequestInfo *s_pendingRequests_socket3 = NULL;
212#endif
213
214#if (SIM_COUNT >= 4)
215static struct ril_event s_commands_event_socket4;
216static struct ril_event s_listen_event_socket4;
217static SocketListenParam s_ril_param_socket4;
218
219static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
220static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
221static RequestInfo *s_pendingRequests_socket4 = NULL;
222#endif
223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static struct ril_event s_wake_timeout_event;
225static struct ril_event s_debug_event;
226
227
228static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
229
Etan Cohend3652192014-06-20 08:28:44 -0700230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233
234static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
236
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800237static RequestInfo *s_toDispatchHead = NULL;
238static RequestInfo *s_toDispatchTail = NULL;
239
240static UserCallbackInfo *s_last_wake_timeout_info = NULL;
241
242static void *s_lastNITZTimeData = NULL;
243static size_t s_lastNITZTimeDataSize;
244
245#if RILC_LOG
246 static char printBuf[PRINTBUF_SIZE];
247#endif
248
249/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700250static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800251
252static void dispatchVoid (Parcel& p, RequestInfo *pRI);
253static void dispatchString (Parcel& p, RequestInfo *pRI);
254static void dispatchStrings (Parcel& p, RequestInfo *pRI);
255static void dispatchInts (Parcel& p, RequestInfo *pRI);
256static void dispatchDial (Parcel& p, RequestInfo *pRI);
257static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800258static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
260static void dispatchRaw(Parcel& p, RequestInfo *pRI);
261static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700262static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800263static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700264static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800265static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800266
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700268static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
269static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
270static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700272static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700273static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
274static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800275static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
276static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700277static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700278static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000279static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800280static int responseInts(Parcel &p, void *response, size_t responselen);
281static int responseStrings(Parcel &p, void *response, size_t responselen);
282static int responseString(Parcel &p, void *response, size_t responselen);
283static int responseVoid(Parcel &p, void *response, size_t responselen);
284static int responseCallList(Parcel &p, void *response, size_t responselen);
285static int responseSMS(Parcel &p, void *response, size_t responselen);
286static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
287static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700288static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800289static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800290static int responseRaw(Parcel &p, void *response, size_t responselen);
291static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700292static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700293static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
294static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700295static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800296static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700297static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
298static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
299static int responseCallRing(Parcel &p, void *response, size_t responselen);
300static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
301static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800302static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700303static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700304static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700305static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800306
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800307static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
308static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
309static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
310
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800311#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700312#if defined(ANDROID_MULTI_SIM)
313extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
314 size_t datalen, RIL_SOCKET_ID socket_id);
315#else
Wink Saville7f856802009-06-09 10:23:37 -0700316extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800317 size_t datalen);
318#endif
Etan Cohend3652192014-06-20 08:28:44 -0700319#endif
320
321#if defined(ANDROID_MULTI_SIM)
322#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
323#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
324#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
325#else
326#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
327#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
328#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
329#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800330
Wink Saville7f856802009-06-09 10:23:37 -0700331static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700332 (RIL_TimedCallback callback, void *param,
333 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800334
335/** Index == requestNumber */
336static CommandInfo s_commands[] = {
337#include "ril_commands.h"
338};
339
340static UnsolResponseInfo s_unsolResponses[] = {
341#include "ril_unsol_commands.h"
342};
343
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800344/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
345 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
346 radio state message and store it. Every time there is a change in Radio State
347 check to see if voice radio tech changes and notify telephony
348 */
349int voiceRadioTech = -1;
350
351/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
352 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
353 source from radio state and store it. Every time there is a change in Radio State
354 check to see if subscription source changed and notify telephony
355 */
356int cdmaSubscriptionSource = -1;
357
358/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
359 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
360 check to see if SIM/RUIM status changed and notify telephony
361 */
362int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800363
Etan Cohend3652192014-06-20 08:28:44 -0700364static char * RIL_getRilSocketName() {
365 return rild;
366}
367
368extern "C"
369void RIL_setRilSocketName(char * s) {
370 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
371}
372
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800373static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700374strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800375 size_t stringlen;
376 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700379
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 return strndup16to8(s16, stringlen);
381}
382
Wink Savillef4c4d362009-04-02 01:37:03 -0700383static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800384 char16_t *s16;
385 size_t s16_len;
386 s16 = strdup8to16(s, &s16_len);
387 p.writeString16(s16, s16_len);
388 free(s16);
389}
390
391
392static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700393memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800394 if (s != NULL) {
395 memset (s, 0, strlen(s));
396 }
397}
398
399void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
400 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700401 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800402 // do nothing -- the data reference lives longer than the Parcel object
403}
404
Wink Saville7f856802009-06-09 10:23:37 -0700405/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800406 * To be called from dispatch thread
407 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700408 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 */
410static void
Etan Cohend3652192014-06-20 08:28:44 -0700411issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800412 RequestInfo *pRI;
413 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700414 /* Hook for current context */
415 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
416 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
417 /* pendingRequestsHook refer to &s_pendingRequests */
418 RequestInfo** pendingRequestsHook = &s_pendingRequests;
419
420#if (SIM_COUNT == 2)
421 if (socket_id == RIL_SOCKET_2) {
422 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
423 pendingRequestsHook = &s_pendingRequests_socket2;
424 }
425#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800426
427 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
428
429 pRI->local = 1;
430 pRI->token = 0xffffffff; // token is not used in this context
431 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700432 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433
Etan Cohend3652192014-06-20 08:28:44 -0700434 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800435 assert (ret == 0);
436
Etan Cohend3652192014-06-20 08:28:44 -0700437 pRI->p_next = *pendingRequestsHook;
438 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800439
Etan Cohend3652192014-06-20 08:28:44 -0700440 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800441 assert (ret == 0);
442
Wink Saville8eb2a122012-11-19 16:05:13 -0800443 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800444
Etan Cohend3652192014-06-20 08:28:44 -0700445 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800446}
447
448
449
450static int
Etan Cohend3652192014-06-20 08:28:44 -0700451processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800452 Parcel p;
453 status_t status;
454 int32_t request;
455 int32_t token;
456 RequestInfo *pRI;
457 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700458 /* Hook for current context */
459 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
460 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
461 /* pendingRequestsHook refer to &s_pendingRequests */
462 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463
464 p.setData((uint8_t *) buffer, buflen);
465
466 // status checked at end
467 status = p.readInt32(&request);
468 status = p.readInt32 (&token);
469
Etan Cohend3652192014-06-20 08:28:44 -0700470 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
471
472#if (SIM_COUNT >= 2)
473 if (socket_id == RIL_SOCKET_2) {
474 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
475 pendingRequestsHook = &s_pendingRequests_socket2;
476 }
477#if (SIM_COUNT >= 3)
478 else if (socket_id == RIL_SOCKET_3) {
479 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
480 pendingRequestsHook = &s_pendingRequests_socket3;
481 }
482#endif
483#if (SIM_COUNT >= 4)
484 else if (socket_id == RIL_SOCKET_4) {
485 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
486 pendingRequestsHook = &s_pendingRequests_socket4;
487 }
488#endif
489#endif
490
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800491 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800492 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800493 return 0;
494 }
495
496 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700497 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800498 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800499 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700500 pErr.writeInt32 (RESPONSE_SOLICITED);
501 pErr.writeInt32 (token);
502 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
503
504 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800505 return 0;
506 }
507
508
509 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
510
511 pRI->token = token;
512 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700513 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514
Etan Cohend3652192014-06-20 08:28:44 -0700515 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 assert (ret == 0);
517
Etan Cohend3652192014-06-20 08:28:44 -0700518 pRI->p_next = *pendingRequestsHook;
519 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520
Etan Cohend3652192014-06-20 08:28:44 -0700521 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800522 assert (ret == 0);
523
524/* sLastDispatchedToken = token; */
525
Wink Saville7f856802009-06-09 10:23:37 -0700526 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800527
528 return 0;
529}
530
531static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700532invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800533 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534 pRI->token, requestToString(pRI->pCI->requestNumber));
535}
536
537/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700538static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700539dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540 clearPrintBuf;
541 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700542 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543}
544
545/** Callee expects const char * */
546static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700547dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800548 status_t status;
549 size_t datalen;
550 size_t stringlen;
551 char *string8 = NULL;
552
553 string8 = strdupReadString(p);
554
555 startRequest;
556 appendPrintBuf("%s%s", printBuf, string8);
557 closeRequest;
558 printRequest(pRI->token, pRI->pCI->requestNumber);
559
Etan Cohend3652192014-06-20 08:28:44 -0700560 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
561 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800562
563#ifdef MEMSET_FREED
564 memsetString(string8);
565#endif
566
567 free(string8);
568 return;
569invalid:
570 invalidCommandBlock(pRI);
571 return;
572}
573
574/** Callee expects const char ** */
575static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700576dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800577 int32_t countStrings;
578 status_t status;
579 size_t datalen;
580 char **pStrings;
581
582 status = p.readInt32 (&countStrings);
583
584 if (status != NO_ERROR) {
585 goto invalid;
586 }
587
588 startRequest;
589 if (countStrings == 0) {
590 // just some non-null pointer
591 pStrings = (char **)alloca(sizeof(char *));
592 datalen = 0;
593 } else if (((int)countStrings) == -1) {
594 pStrings = NULL;
595 datalen = 0;
596 } else {
597 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700598
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800599 pStrings = (char **)alloca(datalen);
600
601 for (int i = 0 ; i < countStrings ; i++) {
602 pStrings[i] = strdupReadString(p);
603 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
604 }
605 }
606 removeLastChar;
607 closeRequest;
608 printRequest(pRI->token, pRI->pCI->requestNumber);
609
Etan Cohend3652192014-06-20 08:28:44 -0700610 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800611
612 if (pStrings != NULL) {
613 for (int i = 0 ; i < countStrings ; i++) {
614#ifdef MEMSET_FREED
615 memsetString (pStrings[i]);
616#endif
617 free(pStrings[i]);
618 }
619
620#ifdef MEMSET_FREED
621 memset(pStrings, 0, datalen);
622#endif
623 }
Wink Saville7f856802009-06-09 10:23:37 -0700624
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800625 return;
626invalid:
627 invalidCommandBlock(pRI);
628 return;
629}
630
631/** Callee expects const int * */
632static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700633dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800634 int32_t count;
635 status_t status;
636 size_t datalen;
637 int *pInts;
638
639 status = p.readInt32 (&count);
640
641 if (status != NO_ERROR || count == 0) {
642 goto invalid;
643 }
644
645 datalen = sizeof(int) * count;
646 pInts = (int *)alloca(datalen);
647
648 startRequest;
649 for (int i = 0 ; i < count ; i++) {
650 int32_t t;
651
652 status = p.readInt32(&t);
653 pInts[i] = (int)t;
654 appendPrintBuf("%s%d,", printBuf, t);
655
656 if (status != NO_ERROR) {
657 goto invalid;
658 }
659 }
660 removeLastChar;
661 closeRequest;
662 printRequest(pRI->token, pRI->pCI->requestNumber);
663
Etan Cohend3652192014-06-20 08:28:44 -0700664 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
665 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800666
667#ifdef MEMSET_FREED
668 memset(pInts, 0, datalen);
669#endif
670
671 return;
672invalid:
673 invalidCommandBlock(pRI);
674 return;
675}
676
677
Wink Saville7f856802009-06-09 10:23:37 -0700678/**
679 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800680 * Payload is:
681 * int32_t status
682 * String pdu
683 */
684static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700685dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800686 RIL_SMS_WriteArgs args;
687 int32_t t;
688 status_t status;
689
690 memset (&args, 0, sizeof(args));
691
692 status = p.readInt32(&t);
693 args.status = (int)t;
694
695 args.pdu = strdupReadString(p);
696
697 if (status != NO_ERROR || args.pdu == NULL) {
698 goto invalid;
699 }
700
701 args.smsc = strdupReadString(p);
702
703 startRequest;
704 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
705 (char*)args.pdu, (char*)args.smsc);
706 closeRequest;
707 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700708
Etan Cohend3652192014-06-20 08:28:44 -0700709 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800710
711#ifdef MEMSET_FREED
712 memsetString (args.pdu);
713#endif
714
715 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700716
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800717#ifdef MEMSET_FREED
718 memset(&args, 0, sizeof(args));
719#endif
720
721 return;
722invalid:
723 invalidCommandBlock(pRI);
724 return;
725}
726
Wink Saville7f856802009-06-09 10:23:37 -0700727/**
728 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800729 * Payload is:
730 * String address
731 * int32_t clir
732 */
733static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700734dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800735 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800736 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800737 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800738 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800739 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800740 status_t status;
741
742 memset (&dial, 0, sizeof(dial));
743
744 dial.address = strdupReadString(p);
745
746 status = p.readInt32(&t);
747 dial.clir = (int)t;
748
749 if (status != NO_ERROR || dial.address == NULL) {
750 goto invalid;
751 }
752
Wink Saville3a4840b2010-04-07 13:29:58 -0700753 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800754 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800755 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800756 } else {
757 status = p.readInt32(&uusPresent);
758
759 if (status != NO_ERROR) {
760 goto invalid;
761 }
762
763 if (uusPresent == 0) {
764 dial.uusInfo = NULL;
765 } else {
766 int32_t len;
767
768 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
769
770 status = p.readInt32(&t);
771 uusInfo.uusType = (RIL_UUS_Type) t;
772
773 status = p.readInt32(&t);
774 uusInfo.uusDcs = (RIL_UUS_DCS) t;
775
776 status = p.readInt32(&len);
777 if (status != NO_ERROR) {
778 goto invalid;
779 }
780
781 // The java code writes -1 for null arrays
782 if (((int) len) == -1) {
783 uusInfo.uusData = NULL;
784 len = 0;
785 } else {
786 uusInfo.uusData = (char*) p.readInplace(len);
787 }
788
789 uusInfo.uusLength = len;
790 dial.uusInfo = &uusInfo;
791 }
Wink Saville7bce0822010-01-08 15:20:12 -0800792 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800793 }
794
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800795 startRequest;
796 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800797 if (uusPresent) {
798 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
799 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
800 dial.uusInfo->uusLength);
801 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800802 closeRequest;
803 printRequest(pRI->token, pRI->pCI->requestNumber);
804
Etan Cohend3652192014-06-20 08:28:44 -0700805 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800806
807#ifdef MEMSET_FREED
808 memsetString (dial.address);
809#endif
810
811 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700812
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800813#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800814 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800815 memset(&dial, 0, sizeof(dial));
816#endif
817
818 return;
819invalid:
820 invalidCommandBlock(pRI);
821 return;
822}
823
Wink Saville7f856802009-06-09 10:23:37 -0700824/**
825 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800826 * Payload is:
827 * int32_t command
828 * int32_t fileid
829 * String path
830 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700831 * String data
832 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800833 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800834 */
835static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700836dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800837 union RIL_SIM_IO {
838 RIL_SIM_IO_v6 v6;
839 RIL_SIM_IO_v5 v5;
840 } simIO;
841
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800842 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800843 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800844 status_t status;
845
846 memset (&simIO, 0, sizeof(simIO));
847
Wink Saville7f856802009-06-09 10:23:37 -0700848 // note we only check status at the end
849
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800850 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800851 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800852
853 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800854 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855
Wink Savillec0114b32011-02-18 10:14:07 -0800856 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800857
858 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800859 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800860
861 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800862 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863
864 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800865 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866
Wink Savillec0114b32011-02-18 10:14:07 -0800867 simIO.v6.data = strdupReadString(p);
868 simIO.v6.pin2 = strdupReadString(p);
869 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800870
871 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800872 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
873 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
874 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
875 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876 closeRequest;
877 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700878
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800879 if (status != NO_ERROR) {
880 goto invalid;
881 }
882
Wink Savillec0114b32011-02-18 10:14:07 -0800883 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700884 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885
886#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800887 memsetString (simIO.v6.path);
888 memsetString (simIO.v6.data);
889 memsetString (simIO.v6.pin2);
890 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891#endif
892
Wink Savillec0114b32011-02-18 10:14:07 -0800893 free (simIO.v6.path);
894 free (simIO.v6.data);
895 free (simIO.v6.pin2);
896 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700897
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898#ifdef MEMSET_FREED
899 memset(&simIO, 0, sizeof(simIO));
900#endif
901
902 return;
903invalid:
904 invalidCommandBlock(pRI);
905 return;
906}
907
908/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800909 * Callee expects const RIL_SIM_APDU *
910 * Payload is:
911 * int32_t sessionid
912 * int32_t cla
913 * int32_t instruction
914 * int32_t p1, p2, p3
915 * String data
916 */
917static void
918dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
919 int32_t t;
920 status_t status;
921 RIL_SIM_APDU apdu;
922
923 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
924
925 // Note we only check status at the end. Any single failure leads to
926 // subsequent reads filing.
927 status = p.readInt32(&t);
928 apdu.sessionid = (int)t;
929
930 status = p.readInt32(&t);
931 apdu.cla = (int)t;
932
933 status = p.readInt32(&t);
934 apdu.instruction = (int)t;
935
936 status = p.readInt32(&t);
937 apdu.p1 = (int)t;
938
939 status = p.readInt32(&t);
940 apdu.p2 = (int)t;
941
942 status = p.readInt32(&t);
943 apdu.p3 = (int)t;
944
945 apdu.data = strdupReadString(p);
946
947 startRequest;
948 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
949 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
950 apdu.p3, (char*)apdu.data);
951 closeRequest;
952 printRequest(pRI->token, pRI->pCI->requestNumber);
953
954 if (status != NO_ERROR) {
955 goto invalid;
956 }
957
Etan Cohend3652192014-06-20 08:28:44 -0700958 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800959
960#ifdef MEMSET_FREED
961 memsetString(apdu.data);
962#endif
963 free(apdu.data);
964
965#ifdef MEMSET_FREED
966 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
967#endif
968
969 return;
970invalid:
971 invalidCommandBlock(pRI);
972 return;
973}
974
975
976/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800977 * Callee expects const RIL_CallForwardInfo *
978 * Payload is:
979 * int32_t status/action
980 * int32_t reason
981 * int32_t serviceCode
982 * int32_t toa
983 * String number (0 length -> null)
984 * int32_t timeSeconds
985 */
Wink Saville7f856802009-06-09 10:23:37 -0700986static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700987dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800988 RIL_CallForwardInfo cff;
989 int32_t t;
990 status_t status;
991
992 memset (&cff, 0, sizeof(cff));
993
Wink Saville7f856802009-06-09 10:23:37 -0700994 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800995
996 status = p.readInt32(&t);
997 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -0700998
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800999 status = p.readInt32(&t);
1000 cff.reason = (int)t;
1001
1002 status = p.readInt32(&t);
1003 cff.serviceClass = (int)t;
1004
1005 status = p.readInt32(&t);
1006 cff.toa = (int)t;
1007
1008 cff.number = strdupReadString(p);
1009
1010 status = p.readInt32(&t);
1011 cff.timeSeconds = (int)t;
1012
1013 if (status != NO_ERROR) {
1014 goto invalid;
1015 }
1016
1017 // special case: number 0-length fields is null
1018
1019 if (cff.number != NULL && strlen (cff.number) == 0) {
1020 cff.number = NULL;
1021 }
1022
1023 startRequest;
1024 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1025 cff.status, cff.reason, cff.serviceClass, cff.toa,
1026 (char*)cff.number, cff.timeSeconds);
1027 closeRequest;
1028 printRequest(pRI->token, pRI->pCI->requestNumber);
1029
Etan Cohend3652192014-06-20 08:28:44 -07001030 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001031
1032#ifdef MEMSET_FREED
1033 memsetString(cff.number);
1034#endif
1035
1036 free (cff.number);
1037
1038#ifdef MEMSET_FREED
1039 memset(&cff, 0, sizeof(cff));
1040#endif
1041
1042 return;
1043invalid:
1044 invalidCommandBlock(pRI);
1045 return;
1046}
1047
1048
Wink Saville7f856802009-06-09 10:23:37 -07001049static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001050dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001051 int32_t len;
1052 status_t status;
1053 const void *data;
1054
1055 status = p.readInt32(&len);
1056
1057 if (status != NO_ERROR) {
1058 goto invalid;
1059 }
1060
1061 // The java code writes -1 for null arrays
1062 if (((int)len) == -1) {
1063 data = NULL;
1064 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001065 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001066
1067 data = p.readInplace(len);
1068
1069 startRequest;
1070 appendPrintBuf("%sraw_size=%d", printBuf, len);
1071 closeRequest;
1072 printRequest(pRI->token, pRI->pCI->requestNumber);
1073
Etan Cohend3652192014-06-20 08:28:44 -07001074 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001075
1076 return;
1077invalid:
1078 invalidCommandBlock(pRI);
1079 return;
1080}
1081
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001082static status_t
1083constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001084 int32_t t;
1085 uint8_t ut;
1086 status_t status;
1087 int32_t digitCount;
1088 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001089
Wink Savillef4c4d362009-04-02 01:37:03 -07001090 memset(&rcsm, 0, sizeof(rcsm));
1091
1092 status = p.readInt32(&t);
1093 rcsm.uTeleserviceID = (int) t;
1094
1095 status = p.read(&ut,sizeof(ut));
1096 rcsm.bIsServicePresent = (uint8_t) ut;
1097
1098 status = p.readInt32(&t);
1099 rcsm.uServicecategory = (int) t;
1100
1101 status = p.readInt32(&t);
1102 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1103
1104 status = p.readInt32(&t);
1105 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1106
1107 status = p.readInt32(&t);
1108 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1109
1110 status = p.readInt32(&t);
1111 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1112
1113 status = p.read(&ut,sizeof(ut));
1114 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1115
1116 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1117 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1118 status = p.read(&ut,sizeof(ut));
1119 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1120 }
1121
Wink Saville7f856802009-06-09 10:23:37 -07001122 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001123 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1124
Wink Saville7f856802009-06-09 10:23:37 -07001125 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001126 rcsm.sSubAddress.odd = (uint8_t) ut;
1127
1128 status = p.read(&ut,sizeof(ut));
1129 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1130
1131 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001132 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1133 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001134 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1135 }
1136
Wink Saville7f856802009-06-09 10:23:37 -07001137 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001138 rcsm.uBearerDataLen = (int) t;
1139
1140 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001141 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1142 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001143 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1144 }
1145
1146 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001147 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001148 }
1149
1150 startRequest;
1151 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001152 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001153 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001154 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001155 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001156
Wink Savillef4c4d362009-04-02 01:37:03 -07001157 printRequest(pRI->token, pRI->pCI->requestNumber);
1158
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001159 return status;
1160}
1161
1162static void
1163dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1164 RIL_CDMA_SMS_Message rcsm;
1165
1166 ALOGD("dispatchCdmaSms");
1167 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1168 goto invalid;
1169 }
1170
Etan Cohend3652192014-06-20 08:28:44 -07001171 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001172
1173#ifdef MEMSET_FREED
1174 memset(&rcsm, 0, sizeof(rcsm));
1175#endif
1176
1177 return;
1178
1179invalid:
1180 invalidCommandBlock(pRI);
1181 return;
1182}
1183
Wink Saville7f856802009-06-09 10:23:37 -07001184static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001185dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1186 RIL_IMS_SMS_Message rism;
1187 RIL_CDMA_SMS_Message rcsm;
1188
1189 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1190
1191 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1192 goto invalid;
1193 }
1194 memset(&rism, 0, sizeof(rism));
1195 rism.tech = RADIO_TECH_3GPP2;
1196 rism.retry = retry;
1197 rism.messageRef = messageRef;
1198 rism.message.cdmaMessage = &rcsm;
1199
Etan Cohend3652192014-06-20 08:28:44 -07001200 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001201 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001202 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001203
1204#ifdef MEMSET_FREED
1205 memset(&rcsm, 0, sizeof(rcsm));
1206 memset(&rism, 0, sizeof(rism));
1207#endif
1208
1209 return;
1210
1211invalid:
1212 invalidCommandBlock(pRI);
1213 return;
1214}
1215
1216static void
1217dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1218 RIL_IMS_SMS_Message rism;
1219 int32_t countStrings;
1220 status_t status;
1221 size_t datalen;
1222 char **pStrings;
1223 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1224
1225 status = p.readInt32 (&countStrings);
1226
1227 if (status != NO_ERROR) {
1228 goto invalid;
1229 }
1230
1231 memset(&rism, 0, sizeof(rism));
1232 rism.tech = RADIO_TECH_3GPP;
1233 rism.retry = retry;
1234 rism.messageRef = messageRef;
1235
1236 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001237 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1238 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001239 if (countStrings == 0) {
1240 // just some non-null pointer
1241 pStrings = (char **)alloca(sizeof(char *));
1242 datalen = 0;
1243 } else if (((int)countStrings) == -1) {
1244 pStrings = NULL;
1245 datalen = 0;
1246 } else {
1247 datalen = sizeof(char *) * countStrings;
1248
1249 pStrings = (char **)alloca(datalen);
1250
1251 for (int i = 0 ; i < countStrings ; i++) {
1252 pStrings[i] = strdupReadString(p);
1253 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1254 }
1255 }
1256 removeLastChar;
1257 closeRequest;
1258 printRequest(pRI->token, pRI->pCI->requestNumber);
1259
1260 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001261 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001262 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001263 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001264
1265 if (pStrings != NULL) {
1266 for (int i = 0 ; i < countStrings ; i++) {
1267#ifdef MEMSET_FREED
1268 memsetString (pStrings[i]);
1269#endif
1270 free(pStrings[i]);
1271 }
1272
1273#ifdef MEMSET_FREED
1274 memset(pStrings, 0, datalen);
1275#endif
1276 }
1277
1278#ifdef MEMSET_FREED
1279 memset(&rism, 0, sizeof(rism));
1280#endif
1281 return;
1282invalid:
1283 ALOGE("dispatchImsGsmSms invalid block");
1284 invalidCommandBlock(pRI);
1285 return;
1286}
1287
1288static void
1289dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1290 int32_t t;
1291 status_t status = p.readInt32(&t);
1292 RIL_RadioTechnologyFamily format;
1293 uint8_t retry;
1294 int32_t messageRef;
1295
1296 ALOGD("dispatchImsSms");
1297 if (status != NO_ERROR) {
1298 goto invalid;
1299 }
1300 format = (RIL_RadioTechnologyFamily) t;
1301
1302 // read retry field
1303 status = p.read(&retry,sizeof(retry));
1304 if (status != NO_ERROR) {
1305 goto invalid;
1306 }
1307 // read messageRef field
1308 status = p.read(&messageRef,sizeof(messageRef));
1309 if (status != NO_ERROR) {
1310 goto invalid;
1311 }
1312
1313 if (RADIO_TECH_3GPP == format) {
1314 dispatchImsGsmSms(p, pRI, retry, messageRef);
1315 } else if (RADIO_TECH_3GPP2 == format) {
1316 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1317 } else {
1318 ALOGE("requestImsSendSMS invalid format value =%d", format);
1319 }
1320
1321 return;
1322
1323invalid:
1324 invalidCommandBlock(pRI);
1325 return;
1326}
1327
1328static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001329dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1330 RIL_CDMA_SMS_Ack rcsa;
1331 int32_t t;
1332 status_t status;
1333 int32_t digitCount;
1334
1335 memset(&rcsa, 0, sizeof(rcsa));
1336
1337 status = p.readInt32(&t);
1338 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1339
1340 status = p.readInt32(&t);
1341 rcsa.uSMSCauseCode = (int) t;
1342
1343 if (status != NO_ERROR) {
1344 goto invalid;
1345 }
1346
1347 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001348 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1349 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001350 closeRequest;
1351
1352 printRequest(pRI->token, pRI->pCI->requestNumber);
1353
Etan Cohend3652192014-06-20 08:28:44 -07001354 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001355
1356#ifdef MEMSET_FREED
1357 memset(&rcsa, 0, sizeof(rcsa));
1358#endif
1359
1360 return;
1361
1362invalid:
1363 invalidCommandBlock(pRI);
1364 return;
1365}
1366
Wink Savillea592eeb2009-05-22 13:26:36 -07001367static void
1368dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1369 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001370 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001371 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001372
Wink Savillea592eeb2009-05-22 13:26:36 -07001373 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001374 if (status != NO_ERROR) {
1375 goto invalid;
1376 }
1377
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001378 {
1379 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1380 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001381
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001382 startRequest;
1383 for (int i = 0 ; i < num ; i++ ) {
1384 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001385
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001386 status = p.readInt32(&t);
1387 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001388
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001389 status = p.readInt32(&t);
1390 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001391
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001392 status = p.readInt32(&t);
1393 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001394
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001395 status = p.readInt32(&t);
1396 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001397
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001398 status = p.readInt32(&t);
1399 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001400
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001401 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1402 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1403 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1404 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1405 gsmBci[i].selected);
1406 }
1407 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001408
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001409 if (status != NO_ERROR) {
1410 goto invalid;
1411 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001412
Etan Cohend3652192014-06-20 08:28:44 -07001413 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001414 gsmBciPtrs,
1415 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001416 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001417
1418#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1420 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001421#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001422 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001423
1424 return;
1425
1426invalid:
1427 invalidCommandBlock(pRI);
1428 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001429}
Wink Savillef4c4d362009-04-02 01:37:03 -07001430
Wink Savillea592eeb2009-05-22 13:26:36 -07001431static void
1432dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1433 int32_t t;
1434 status_t status;
1435 int32_t num;
1436
1437 status = p.readInt32(&num);
1438 if (status != NO_ERROR) {
1439 goto invalid;
1440 }
1441
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001442 {
1443 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1444 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001445
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001446 startRequest;
1447 for (int i = 0 ; i < num ; i++ ) {
1448 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001449
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001450 status = p.readInt32(&t);
1451 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001452
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001453 status = p.readInt32(&t);
1454 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001455
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001456 status = p.readInt32(&t);
1457 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001458
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001459 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1460 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1461 cdmaBci[i].language, cdmaBci[i].selected);
1462 }
1463 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001464
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001465 if (status != NO_ERROR) {
1466 goto invalid;
1467 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001468
Etan Cohend3652192014-06-20 08:28:44 -07001469 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001470 cdmaBciPtrs,
1471 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001472 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001473
1474#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1476 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001477#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
1480 return;
1481
1482invalid:
1483 invalidCommandBlock(pRI);
1484 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001485}
1486
1487static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1488 RIL_CDMA_SMS_WriteArgs rcsw;
1489 int32_t t;
1490 uint32_t ut;
1491 uint8_t uct;
1492 status_t status;
1493 int32_t digitCount;
1494
1495 memset(&rcsw, 0, sizeof(rcsw));
1496
1497 status = p.readInt32(&t);
1498 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001499
Wink Savillef4c4d362009-04-02 01:37:03 -07001500 status = p.readInt32(&t);
1501 rcsw.message.uTeleserviceID = (int) t;
1502
1503 status = p.read(&uct,sizeof(uct));
1504 rcsw.message.bIsServicePresent = (uint8_t) uct;
1505
1506 status = p.readInt32(&t);
1507 rcsw.message.uServicecategory = (int) t;
1508
1509 status = p.readInt32(&t);
1510 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1511
1512 status = p.readInt32(&t);
1513 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1514
1515 status = p.readInt32(&t);
1516 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1517
1518 status = p.readInt32(&t);
1519 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1520
1521 status = p.read(&uct,sizeof(uct));
1522 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1523
1524 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1525 status = p.read(&uct,sizeof(uct));
1526 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1527 }
1528
Wink Savillea592eeb2009-05-22 13:26:36 -07001529 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001530 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1531
Wink Savillea592eeb2009-05-22 13:26:36 -07001532 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001533 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1534
1535 status = p.read(&uct,sizeof(uct));
1536 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1537
1538 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001539 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001540 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1541 }
1542
Wink Savillea592eeb2009-05-22 13:26:36 -07001543 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001544 rcsw.message.uBearerDataLen = (int) t;
1545
1546 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001547 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001548 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1549 }
1550
1551 if (status != NO_ERROR) {
1552 goto invalid;
1553 }
1554
1555 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001556 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1557 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1558 message.sAddress.number_mode=%d, \
1559 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001560 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001561 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1562 rcsw.message.sAddress.number_mode,
1563 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001564 closeRequest;
1565
1566 printRequest(pRI->token, pRI->pCI->requestNumber);
1567
Etan Cohend3652192014-06-20 08:28:44 -07001568 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001569
1570#ifdef MEMSET_FREED
1571 memset(&rcsw, 0, sizeof(rcsw));
1572#endif
1573
1574 return;
1575
1576invalid:
1577 invalidCommandBlock(pRI);
1578 return;
1579
1580}
1581
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001582// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1583// Version 4 of the RIL interface adds a new PDP type parameter to support
1584// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1585// RIL, remove the parameter from the request.
1586static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1587 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1588 const int numParamsRilV3 = 6;
1589
1590 // The first bytes of the RIL parcel contain the request number and the
1591 // serial number - see processCommandBuffer(). Copy them over too.
1592 int pos = p.dataPosition();
1593
1594 int numParams = p.readInt32();
1595 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1596 Parcel p2;
1597 p2.appendFrom(&p, 0, pos);
1598 p2.writeInt32(numParamsRilV3);
1599 for(int i = 0; i < numParamsRilV3; i++) {
1600 p2.writeString16(p.readString16());
1601 }
1602 p2.setDataPosition(pos);
1603 dispatchStrings(p2, pRI);
1604 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001605 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001606 dispatchStrings(p, pRI);
1607 }
1608}
1609
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001610// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1611// When all RILs handle this request, this function can be removed and
1612// the request can be sent directly to the RIL using dispatchVoid.
1613static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001614 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001615
1616 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1617 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1618 }
1619
1620 // RILs that support RADIO_STATE_ON should support this request.
1621 if (RADIO_STATE_ON == state) {
1622 dispatchVoid(p, pRI);
1623 return;
1624 }
1625
1626 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1627 // will not support this new request either and decode Voice Radio Technology
1628 // from Radio State
1629 voiceRadioTech = decodeVoiceRadioTechnology(state);
1630
1631 if (voiceRadioTech < 0)
1632 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1633 else
1634 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1635}
1636
1637// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1638// When all RILs handle this request, this function can be removed and
1639// the request can be sent directly to the RIL using dispatchVoid.
1640static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001641 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001642
1643 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1644 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1645 }
1646
1647 // RILs that support RADIO_STATE_ON should support this request.
1648 if (RADIO_STATE_ON == state) {
1649 dispatchVoid(p, pRI);
1650 return;
1651 }
1652
1653 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1654 // will not support this new request either and decode CDMA Subscription Source
1655 // from Radio State
1656 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1657
1658 if (cdmaSubscriptionSource < 0)
1659 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1660 else
1661 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1662}
1663
Sungmin Choi75697532013-04-26 15:04:45 -07001664static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1665{
1666 RIL_InitialAttachApn pf;
1667 int32_t t;
1668 status_t status;
1669
1670 memset(&pf, 0, sizeof(pf));
1671
1672 pf.apn = strdupReadString(p);
1673 pf.protocol = strdupReadString(p);
1674
1675 status = p.readInt32(&t);
1676 pf.authtype = (int) t;
1677
1678 pf.username = strdupReadString(p);
1679 pf.password = strdupReadString(p);
1680
1681 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001682 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1683 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001684 closeRequest;
1685 printRequest(pRI->token, pRI->pCI->requestNumber);
1686
1687 if (status != NO_ERROR) {
1688 goto invalid;
1689 }
Etan Cohend3652192014-06-20 08:28:44 -07001690 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001691
1692#ifdef MEMSET_FREED
1693 memsetString(pf.apn);
1694 memsetString(pf.protocol);
1695 memsetString(pf.username);
1696 memsetString(pf.password);
1697#endif
1698
1699 free(pf.apn);
1700 free(pf.protocol);
1701 free(pf.username);
1702 free(pf.password);
1703
1704#ifdef MEMSET_FREED
1705 memset(&pf, 0, sizeof(pf));
1706#endif
1707
1708 return;
1709invalid:
1710 invalidCommandBlock(pRI);
1711 return;
1712}
1713
Jake Hamby8a4a2332014-01-15 13:12:05 -08001714static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1715 RIL_NV_ReadItem nvri;
1716 int32_t t;
1717 status_t status;
1718
1719 memset(&nvri, 0, sizeof(nvri));
1720
1721 status = p.readInt32(&t);
1722 nvri.itemID = (RIL_NV_Item) t;
1723
1724 if (status != NO_ERROR) {
1725 goto invalid;
1726 }
1727
1728 startRequest;
1729 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1730 closeRequest;
1731
1732 printRequest(pRI->token, pRI->pCI->requestNumber);
1733
Etan Cohend3652192014-06-20 08:28:44 -07001734 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001735
1736#ifdef MEMSET_FREED
1737 memset(&nvri, 0, sizeof(nvri));
1738#endif
1739
1740 return;
1741
1742invalid:
1743 invalidCommandBlock(pRI);
1744 return;
1745}
1746
1747static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1748 RIL_NV_WriteItem nvwi;
1749 int32_t t;
1750 status_t status;
1751
1752 memset(&nvwi, 0, sizeof(nvwi));
1753
1754 status = p.readInt32(&t);
1755 nvwi.itemID = (RIL_NV_Item) t;
1756
1757 nvwi.value = strdupReadString(p);
1758
1759 if (status != NO_ERROR || nvwi.value == NULL) {
1760 goto invalid;
1761 }
1762
1763 startRequest;
1764 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1765 nvwi.value);
1766 closeRequest;
1767
1768 printRequest(pRI->token, pRI->pCI->requestNumber);
1769
Etan Cohend3652192014-06-20 08:28:44 -07001770 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001771
1772#ifdef MEMSET_FREED
1773 memsetString(nvwi.value);
1774#endif
1775
1776 free(nvwi.value);
1777
1778#ifdef MEMSET_FREED
1779 memset(&nvwi, 0, sizeof(nvwi));
1780#endif
1781
1782 return;
1783
1784invalid:
1785 invalidCommandBlock(pRI);
1786 return;
1787}
1788
1789
Etan Cohend3652192014-06-20 08:28:44 -07001790static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1791 RIL_SelectUiccSub uicc_sub;
1792 status_t status;
1793 int32_t t;
1794 memset(&uicc_sub, 0, sizeof(uicc_sub));
1795
1796 status = p.readInt32(&t);
1797 if (status != NO_ERROR) {
1798 goto invalid;
1799 }
1800 uicc_sub.slot = (int) t;
1801
1802 status = p.readInt32(&t);
1803 if (status != NO_ERROR) {
1804 goto invalid;
1805 }
1806 uicc_sub.app_index = (int) t;
1807
1808 status = p.readInt32(&t);
1809 if (status != NO_ERROR) {
1810 goto invalid;
1811 }
1812 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1813
1814 status = p.readInt32(&t);
1815 if (status != NO_ERROR) {
1816 goto invalid;
1817 }
1818 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1819
1820 startRequest;
1821 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1822 uicc_sub.act_status);
1823 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1824 uicc_sub.app_index, uicc_sub.act_status);
1825 closeRequest;
1826 printRequest(pRI->token, pRI->pCI->requestNumber);
1827
1828 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1829
1830#ifdef MEMSET_FREED
1831 memset(&uicc_sub, 0, sizeof(uicc_sub));
1832#endif
1833 return;
1834
1835invalid:
1836 invalidCommandBlock(pRI);
1837 return;
1838}
1839
Amit Mahajan90530a62014-07-01 15:54:08 -07001840static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1841{
1842 RIL_SimAuthentication pf;
1843 int32_t t;
1844 status_t status;
1845
1846 memset(&pf, 0, sizeof(pf));
1847
1848 status = p.readInt32(&t);
1849 pf.authContext = (int) t;
1850 pf.authData = strdupReadString(p);
1851 pf.aid = strdupReadString(p);
1852
1853 startRequest;
1854 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1855 closeRequest;
1856 printRequest(pRI->token, pRI->pCI->requestNumber);
1857
1858 if (status != NO_ERROR) {
1859 goto invalid;
1860 }
1861 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1862
1863#ifdef MEMSET_FREED
1864 memsetString(pf.authData);
1865 memsetString(pf.aid);
1866#endif
1867
1868 free(pf.authData);
1869 free(pf.aid);
1870
1871#ifdef MEMSET_FREED
1872 memset(&pf, 0, sizeof(pf));
1873#endif
1874
1875 return;
1876invalid:
1877 invalidCommandBlock(pRI);
1878 return;
1879}
1880
Amit Mahajanc796e222014-08-13 16:54:01 +00001881static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1882 int32_t t;
1883 status_t status;
1884 int32_t num;
1885
1886 status = p.readInt32(&num);
1887 if (status != NO_ERROR) {
1888 goto invalid;
1889 }
1890
1891 {
1892 RIL_DataProfileInfo dataProfiles[num];
1893 RIL_DataProfileInfo *dataProfilePtrs[num];
1894
1895 startRequest;
1896 for (int i = 0 ; i < num ; i++ ) {
1897 dataProfilePtrs[i] = &dataProfiles[i];
1898
1899 status = p.readInt32(&t);
1900 dataProfiles[i].profileId = (int) t;
1901
1902 dataProfiles[i].apn = strdupReadString(p);
1903 dataProfiles[i].protocol = strdupReadString(p);
1904 status = p.readInt32(&t);
1905 dataProfiles[i].authType = (int) t;
1906
1907 dataProfiles[i].user = strdupReadString(p);
1908 dataProfiles[i].password = strdupReadString(p);
1909
1910 status = p.readInt32(&t);
1911 dataProfiles[i].type = (int) t;
1912
1913 status = p.readInt32(&t);
1914 dataProfiles[i].maxConnsTime = (int) t;
1915 status = p.readInt32(&t);
1916 dataProfiles[i].maxConns = (int) t;
1917 status = p.readInt32(&t);
1918 dataProfiles[i].waitTime = (int) t;
1919
1920 status = p.readInt32(&t);
1921 dataProfiles[i].enabled = (int) t;
1922
1923 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1924 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1925 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1926 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1927 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1928 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1929 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1930 }
1931 closeRequest;
1932 printRequest(pRI->token, pRI->pCI->requestNumber);
1933
1934 if (status != NO_ERROR) {
1935 goto invalid;
1936 }
1937 CALL_ONREQUEST(pRI->pCI->requestNumber,
1938 dataProfilePtrs,
1939 num * sizeof(RIL_DataProfileInfo *),
1940 pRI, pRI->socket_id);
1941
1942#ifdef MEMSET_FREED
1943 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1944 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1945#endif
1946 }
1947
1948 return;
1949
1950invalid:
1951 invalidCommandBlock(pRI);
1952 return;
1953}
1954
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001955static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001956blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07001957 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001958 const uint8_t *toWrite;
1959
1960 toWrite = (const uint8_t *)buffer;
1961
1962 while (writeOffset < len) {
1963 ssize_t written;
1964 do {
1965 written = write (fd, toWrite + writeOffset,
1966 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05301967 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001968
1969 if (written >= 0) {
1970 writeOffset += written;
1971 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08001972 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001973 close(fd);
1974 return -1;
1975 }
1976 }
1977
1978 return 0;
1979}
1980
1981static int
Etan Cohend3652192014-06-20 08:28:44 -07001982sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1983 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001984 int ret;
1985 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07001986 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001987
Etan Cohend3652192014-06-20 08:28:44 -07001988 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1989
1990#if (SIM_COUNT >= 2)
1991 if (socket_id == RIL_SOCKET_2) {
1992 fd = s_ril_param_socket2.fdCommand;
1993 writeMutexHook = &s_writeMutex_socket2;
1994 }
1995#if (SIM_COUNT >= 3)
1996 else if (socket_id == RIL_SOCKET_3) {
1997 fd = s_ril_param_socket3.fdCommand;
1998 writeMutexHook = &s_writeMutex_socket3;
1999 }
2000#endif
2001#if (SIM_COUNT >= 4)
2002 else if (socket_id == RIL_SOCKET_4) {
2003 fd = s_ril_param_socket4.fdCommand;
2004 writeMutexHook = &s_writeMutex_socket4;
2005 }
2006#endif
2007#endif
2008 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002009 return -1;
2010 }
2011
2012 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002013 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002014 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2015
2016 return -1;
2017 }
Wink Saville7f856802009-06-09 10:23:37 -07002018
Etan Cohend3652192014-06-20 08:28:44 -07002019 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002020
2021 header = htonl(dataSize);
2022
2023 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2024
2025 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002026 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002027 return ret;
2028 }
2029
Kennyee1fadc2009-08-13 00:45:53 +08002030 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002031
2032 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002033 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002034 return ret;
2035 }
2036
Etan Cohend3652192014-06-20 08:28:44 -07002037 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002038
2039 return 0;
2040}
2041
2042static int
Etan Cohend3652192014-06-20 08:28:44 -07002043sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002044 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002045 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002046}
2047
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002048/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002049
2050static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002051responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002052 int numInts;
2053
2054 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002055 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002056 return RIL_ERRNO_INVALID_RESPONSE;
2057 }
2058 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002059 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002060 (int)responselen, (int)sizeof(int));
2061 return RIL_ERRNO_INVALID_RESPONSE;
2062 }
2063
2064 int *p_int = (int *) response;
2065
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002066 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002067 p.writeInt32 (numInts);
2068
2069 /* each int*/
2070 startResponse;
2071 for (int i = 0 ; i < numInts ; i++) {
2072 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2073 p.writeInt32(p_int[i]);
2074 }
2075 removeLastChar;
2076 closeResponse;
2077
2078 return 0;
2079}
2080
Wink Saville43808972011-01-13 17:39:51 -08002081/** response is a char **, pointing to an array of char *'s
2082 The parcel will begin with the version */
2083static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2084 p.writeInt32(version);
2085 return responseStrings(p, response, responselen);
2086}
2087
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002088/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002089static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002090 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002091
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002092 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002093 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002094 return RIL_ERRNO_INVALID_RESPONSE;
2095 }
2096 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002097 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002098 (int)responselen, (int)sizeof(char *));
2099 return RIL_ERRNO_INVALID_RESPONSE;
2100 }
2101
2102 if (response == NULL) {
2103 p.writeInt32 (0);
2104 } else {
2105 char **p_cur = (char **) response;
2106
2107 numStrings = responselen / sizeof(char *);
2108 p.writeInt32 (numStrings);
2109
2110 /* each string*/
2111 startResponse;
2112 for (int i = 0 ; i < numStrings ; i++) {
2113 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2114 writeStringToParcel (p, p_cur[i]);
2115 }
2116 removeLastChar;
2117 closeResponse;
2118 }
2119 return 0;
2120}
2121
2122
2123/**
Wink Saville7f856802009-06-09 10:23:37 -07002124 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002125 * FIXME currently ignores responselen
2126 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002127static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002128 /* one string only */
2129 startResponse;
2130 appendPrintBuf("%s%s", printBuf, (char*)response);
2131 closeResponse;
2132
2133 writeStringToParcel(p, (const char *)response);
2134
2135 return 0;
2136}
2137
Wink Savillef4c4d362009-04-02 01:37:03 -07002138static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002139 startResponse;
2140 removeLastChar;
2141 return 0;
2142}
2143
Wink Savillef4c4d362009-04-02 01:37:03 -07002144static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002145 int num;
2146
2147 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002148 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002149 return RIL_ERRNO_INVALID_RESPONSE;
2150 }
2151
2152 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002153 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002154 (int)responselen, (int)sizeof (RIL_Call *));
2155 return RIL_ERRNO_INVALID_RESPONSE;
2156 }
2157
2158 startResponse;
2159 /* number of call info's */
2160 num = responselen / sizeof(RIL_Call *);
2161 p.writeInt32(num);
2162
2163 for (int i = 0 ; i < num ; i++) {
2164 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2165 /* each call info */
2166 p.writeInt32(p_cur->state);
2167 p.writeInt32(p_cur->index);
2168 p.writeInt32(p_cur->toa);
2169 p.writeInt32(p_cur->isMpty);
2170 p.writeInt32(p_cur->isMT);
2171 p.writeInt32(p_cur->als);
2172 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002173 p.writeInt32(p_cur->isVoicePrivacy);
2174 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002175 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002176 writeStringToParcel(p, p_cur->name);
2177 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002178 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002179 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2180 p.writeInt32(0); /* UUS Information is absent */
2181 } else {
2182 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2183 p.writeInt32(1); /* UUS Information is present */
2184 p.writeInt32(uusInfo->uusType);
2185 p.writeInt32(uusInfo->uusDcs);
2186 p.writeInt32(uusInfo->uusLength);
2187 p.write(uusInfo->uusData, uusInfo->uusLength);
2188 }
Wink Saville3d54e742009-05-18 18:00:44 -07002189 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002190 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002191 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002192 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002193 p_cur->toa);
2194 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2195 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002196 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002197 (p_cur->isMT)?"mt":"mo",
2198 p_cur->als,
2199 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002200 (p_cur->isVoicePrivacy)?"evp":"noevp");
2201 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2202 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002203 p_cur->number,
2204 p_cur->numberPresentation,
2205 p_cur->name,
2206 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002207 }
2208 removeLastChar;
2209 closeResponse;
2210
2211 return 0;
2212}
2213
Wink Savillef4c4d362009-04-02 01:37:03 -07002214static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002215 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002216 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002217 return RIL_ERRNO_INVALID_RESPONSE;
2218 }
2219
2220 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002221 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002222 (int)responselen, (int)sizeof (RIL_SMS_Response));
2223 return RIL_ERRNO_INVALID_RESPONSE;
2224 }
2225
2226 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2227
2228 p.writeInt32(p_cur->messageRef);
2229 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002230 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002231
2232 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002233 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2234 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002235 closeResponse;
2236
2237 return 0;
2238}
2239
Wink Savillec0114b32011-02-18 10:14:07 -08002240static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002241{
2242 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002243 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002244 return RIL_ERRNO_INVALID_RESPONSE;
2245 }
2246
Wink Savillec0114b32011-02-18 10:14:07 -08002247 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002248 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002249 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002250 return RIL_ERRNO_INVALID_RESPONSE;
2251 }
2252
Amit Mahajan52500162014-07-29 17:36:48 -07002253 // Write version
2254 p.writeInt32(4);
2255
Wink Savillec0114b32011-02-18 10:14:07 -08002256 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002257 p.writeInt32(num);
2258
Wink Savillec0114b32011-02-18 10:14:07 -08002259 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002260 startResponse;
2261 int i;
2262 for (i = 0; i < num; i++) {
2263 p.writeInt32(p_cur[i].cid);
2264 p.writeInt32(p_cur[i].active);
2265 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002266 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002267 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002268 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002269 p_cur[i].cid,
2270 (p_cur[i].active==0)?"down":"up",
2271 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002272 (char*)p_cur[i].address);
2273 }
2274 removeLastChar;
2275 closeResponse;
2276
2277 return 0;
2278}
2279
Etan Cohend3652192014-06-20 08:28:44 -07002280static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2281{
Amit Mahajan52500162014-07-29 17:36:48 -07002282 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002283 RLOGE("invalid response: NULL");
2284 return RIL_ERRNO_INVALID_RESPONSE;
2285 }
2286
2287 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002288 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002289 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2290 return RIL_ERRNO_INVALID_RESPONSE;
2291 }
2292
Amit Mahajan52500162014-07-29 17:36:48 -07002293 // Write version
2294 p.writeInt32(6);
2295
Etan Cohend3652192014-06-20 08:28:44 -07002296 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2297 p.writeInt32(num);
2298
2299 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2300 startResponse;
2301 int i;
2302 for (i = 0; i < num; i++) {
2303 p.writeInt32((int)p_cur[i].status);
2304 p.writeInt32(p_cur[i].suggestedRetryTime);
2305 p.writeInt32(p_cur[i].cid);
2306 p.writeInt32(p_cur[i].active);
2307 writeStringToParcel(p, p_cur[i].type);
2308 writeStringToParcel(p, p_cur[i].ifname);
2309 writeStringToParcel(p, p_cur[i].addresses);
2310 writeStringToParcel(p, p_cur[i].dnses);
2311 writeStringToParcel(p, p_cur[i].gateways);
2312 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2313 p_cur[i].status,
2314 p_cur[i].suggestedRetryTime,
2315 p_cur[i].cid,
2316 (p_cur[i].active==0)?"down":"up",
2317 (char*)p_cur[i].type,
2318 (char*)p_cur[i].ifname,
2319 (char*)p_cur[i].addresses,
2320 (char*)p_cur[i].dnses,
2321 (char*)p_cur[i].gateways);
2322 }
2323 removeLastChar;
2324 closeResponse;
2325
2326 return 0;
2327}
2328
Wink Saville43808972011-01-13 17:39:51 -08002329static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2330{
Wink Saville43808972011-01-13 17:39:51 -08002331 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002332 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002333 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002334 } else {
2335 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002336 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002337 return RIL_ERRNO_INVALID_RESPONSE;
2338 }
2339
Etan Cohend3652192014-06-20 08:28:44 -07002340 // Support v6 or v9 with new rils
2341 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002342 RLOGD("responseDataCallList: v6");
Etan Cohend3652192014-06-20 08:28:44 -07002343 return responseDataCallListV6(p, response, responselen);
2344 }
2345
2346 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002347 RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002348 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002349 return RIL_ERRNO_INVALID_RESPONSE;
2350 }
2351
Amit Mahajan52500162014-07-29 17:36:48 -07002352 // Write version
2353 p.writeInt32(10);
2354
Etan Cohend3652192014-06-20 08:28:44 -07002355 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002356 p.writeInt32(num);
2357
Etan Cohend3652192014-06-20 08:28:44 -07002358 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002359 startResponse;
2360 int i;
2361 for (i = 0; i < num; i++) {
2362 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002363 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002364 p.writeInt32(p_cur[i].cid);
2365 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002366 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002367 writeStringToParcel(p, p_cur[i].ifname);
2368 writeStringToParcel(p, p_cur[i].addresses);
2369 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002370 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002371 writeStringToParcel(p, p_cur[i].pcscf);
2372 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002373 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002374 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002375 p_cur[i].cid,
2376 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002377 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002378 (char*)p_cur[i].ifname,
2379 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002380 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002381 (char*)p_cur[i].gateways,
2382 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002383 }
2384 removeLastChar;
2385 closeResponse;
2386 }
2387
2388 return 0;
2389}
2390
2391static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2392{
2393 if (s_callbacks.version < 5) {
2394 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2395 } else {
2396 return responseDataCallList(p, response, responselen);
2397 }
2398}
2399
Wink Savillef4c4d362009-04-02 01:37:03 -07002400static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002401 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002402 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002403 return RIL_ERRNO_INVALID_RESPONSE;
2404 }
2405
2406 // The java code reads -1 size as null byte array
2407 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002408 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002409 } else {
2410 p.writeInt32(responselen);
2411 p.write(response, responselen);
2412 }
2413
2414 return 0;
2415}
2416
2417
Wink Savillef4c4d362009-04-02 01:37:03 -07002418static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002419 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002420 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002421 return RIL_ERRNO_INVALID_RESPONSE;
2422 }
2423
2424 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002425 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002426 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2427 return RIL_ERRNO_INVALID_RESPONSE;
2428 }
2429
2430 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2431 p.writeInt32(p_cur->sw1);
2432 p.writeInt32(p_cur->sw2);
2433 writeStringToParcel(p, p_cur->simResponse);
2434
2435 startResponse;
2436 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2437 (char*)p_cur->simResponse);
2438 closeResponse;
2439
2440
2441 return 0;
2442}
2443
Wink Savillef4c4d362009-04-02 01:37:03 -07002444static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002445 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002446
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002447 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002448 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002449 return RIL_ERRNO_INVALID_RESPONSE;
2450 }
2451
2452 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002453 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002454 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2455 return RIL_ERRNO_INVALID_RESPONSE;
2456 }
2457
2458 /* number of call info's */
2459 num = responselen / sizeof(RIL_CallForwardInfo *);
2460 p.writeInt32(num);
2461
2462 startResponse;
2463 for (int i = 0 ; i < num ; i++) {
2464 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2465
2466 p.writeInt32(p_cur->status);
2467 p.writeInt32(p_cur->reason);
2468 p.writeInt32(p_cur->serviceClass);
2469 p.writeInt32(p_cur->toa);
2470 writeStringToParcel(p, p_cur->number);
2471 p.writeInt32(p_cur->timeSeconds);
2472 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2473 (p_cur->status==1)?"enable":"disable",
2474 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2475 (char*)p_cur->number,
2476 p_cur->timeSeconds);
2477 }
2478 removeLastChar;
2479 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002480
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002481 return 0;
2482}
2483
Wink Savillef4c4d362009-04-02 01:37:03 -07002484static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002485 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002486 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002487 return RIL_ERRNO_INVALID_RESPONSE;
2488 }
2489
2490 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002491 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002492 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2493 return RIL_ERRNO_INVALID_RESPONSE;
2494 }
2495
2496 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2497 p.writeInt32(p_cur->notificationType);
2498 p.writeInt32(p_cur->code);
2499 p.writeInt32(p_cur->index);
2500 p.writeInt32(p_cur->type);
2501 writeStringToParcel(p, p_cur->number);
2502
2503 startResponse;
2504 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2505 (p_cur->notificationType==0)?"mo":"mt",
2506 p_cur->code, p_cur->index, p_cur->type,
2507 (char*)p_cur->number);
2508 closeResponse;
2509
2510 return 0;
2511}
2512
Wink Saville3d54e742009-05-18 18:00:44 -07002513static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002514 int num;
2515
2516 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002517 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002518 return RIL_ERRNO_INVALID_RESPONSE;
2519 }
2520
2521 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002522 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002523 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2524 return RIL_ERRNO_INVALID_RESPONSE;
2525 }
2526
2527 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002528 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002529 num = responselen / sizeof(RIL_NeighboringCell *);
2530 p.writeInt32(num);
2531
2532 for (int i = 0 ; i < num ; i++) {
2533 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2534
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002535 p.writeInt32(p_cur->rssi);
2536 writeStringToParcel (p, p_cur->cid);
2537
2538 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2539 p_cur->cid, p_cur->rssi);
2540 }
2541 removeLastChar;
2542 closeResponse;
2543
2544 return 0;
2545}
2546
Wink Saville3d54e742009-05-18 18:00:44 -07002547/**
2548 * Marshall the signalInfoRecord into the parcel if it exists.
2549 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002550static void marshallSignalInfoRecord(Parcel &p,
2551 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002552 p.writeInt32(p_signalInfoRecord.isPresent);
2553 p.writeInt32(p_signalInfoRecord.signalType);
2554 p.writeInt32(p_signalInfoRecord.alertPitch);
2555 p.writeInt32(p_signalInfoRecord.signal);
2556}
2557
Wink Savillea592eeb2009-05-22 13:26:36 -07002558static int responseCdmaInformationRecords(Parcel &p,
2559 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002560 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002561 char* string8 = NULL;
2562 int buffer_lenght;
2563 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002564
2565 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002566 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002567 return RIL_ERRNO_INVALID_RESPONSE;
2568 }
2569
Wink Savillea592eeb2009-05-22 13:26:36 -07002570 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002571 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002572 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002573 return RIL_ERRNO_INVALID_RESPONSE;
2574 }
2575
Wink Savillea592eeb2009-05-22 13:26:36 -07002576 RIL_CDMA_InformationRecords *p_cur =
2577 (RIL_CDMA_InformationRecords *) response;
2578 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002579
2580 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002581 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002582
Wink Savillea592eeb2009-05-22 13:26:36 -07002583 for (int i = 0 ; i < num ; i++) {
2584 infoRec = &p_cur->infoRec[i];
2585 p.writeInt32(infoRec->name);
2586 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002587 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002588 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2589 if (infoRec->rec.display.alpha_len >
2590 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002591 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002592 expected not more than %d\n",
2593 (int)infoRec->rec.display.alpha_len,
2594 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2595 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002596 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002597 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2598 * sizeof(char) );
2599 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2600 string8[i] = infoRec->rec.display.alpha_buf[i];
2601 }
Wink Saville43808972011-01-13 17:39:51 -08002602 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002603 writeStringToParcel(p, (const char*)string8);
2604 free(string8);
2605 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002606 break;
2607 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002608 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002609 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002610 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002611 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002612 expected not more than %d\n",
2613 (int)infoRec->rec.number.len,
2614 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2615 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002616 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002617 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2618 * sizeof(char) );
2619 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2620 string8[i] = infoRec->rec.number.buf[i];
2621 }
Wink Saville43808972011-01-13 17:39:51 -08002622 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002623 writeStringToParcel(p, (const char*)string8);
2624 free(string8);
2625 string8 = NULL;
2626 p.writeInt32(infoRec->rec.number.number_type);
2627 p.writeInt32(infoRec->rec.number.number_plan);
2628 p.writeInt32(infoRec->rec.number.pi);
2629 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002630 break;
2631 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002632 p.writeInt32(infoRec->rec.signal.isPresent);
2633 p.writeInt32(infoRec->rec.signal.signalType);
2634 p.writeInt32(infoRec->rec.signal.alertPitch);
2635 p.writeInt32(infoRec->rec.signal.signal);
2636
2637 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2638 alertPitch=%X, signal=%X, ",
2639 printBuf, (int)infoRec->rec.signal.isPresent,
2640 (int)infoRec->rec.signal.signalType,
2641 (int)infoRec->rec.signal.alertPitch,
2642 (int)infoRec->rec.signal.signal);
2643 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002644 break;
2645 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002646 if (infoRec->rec.redir.redirectingNumber.len >
2647 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002648 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002649 expected not more than %d\n",
2650 (int)infoRec->rec.redir.redirectingNumber.len,
2651 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2652 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002653 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002654 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2655 .len + 1) * sizeof(char) );
2656 for (int i = 0;
2657 i < infoRec->rec.redir.redirectingNumber.len;
2658 i++) {
2659 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2660 }
Wink Saville43808972011-01-13 17:39:51 -08002661 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002662 writeStringToParcel(p, (const char*)string8);
2663 free(string8);
2664 string8 = NULL;
2665 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2666 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2667 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2668 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2669 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002670 break;
2671 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002672 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2673 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2674 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2675 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2676
2677 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2678 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2679 lineCtrlPowerDenial=%d, ", printBuf,
2680 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2681 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2682 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2683 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2684 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002685 break;
2686 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002687 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002688
Wink Savillea592eeb2009-05-22 13:26:36 -07002689 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2690 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002691 break;
2692 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002693 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2694 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2695
2696 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2697 infoRec->rec.audioCtrl.upLink,
2698 infoRec->rec.audioCtrl.downLink);
2699 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002700 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002701 case RIL_CDMA_T53_RELEASE_INFO_REC:
2702 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002703 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002704 return RIL_ERRNO_INVALID_RESPONSE;
2705 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002706 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002707 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002708 }
2709 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002710 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002711
Wink Savillea592eeb2009-05-22 13:26:36 -07002712 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002713}
2714
Wink Savillea592eeb2009-05-22 13:26:36 -07002715static int responseRilSignalStrength(Parcel &p,
2716 void *response, size_t responselen) {
2717 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002718 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002719 return RIL_ERRNO_INVALID_RESPONSE;
2720 }
2721
Wink Savillec0114b32011-02-18 10:14:07 -08002722 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002723 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002724
Wink Saville3d54e742009-05-18 18:00:44 -07002725 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2726 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2727 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2728 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2729 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2730 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2731 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002732 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002733 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002734 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002735 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002736 if (s_callbacks.version <= 6) {
2737 // signalStrength: -1 -> 99
2738 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2739 p_cur->LTE_SignalStrength.signalStrength = 99;
2740 }
2741 // rsrp: -1 -> INT_MAX all other negative value to positive.
2742 // So remap here
2743 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2744 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2745 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2746 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2747 }
2748 // rsrq: -1 -> INT_MAX
2749 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2750 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2751 }
2752 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002753
Wink Saville18e4ab12013-04-07 17:31:04 -07002754 // cqi: -1 -> INT_MAX
2755 if (p_cur->LTE_SignalStrength.cqi == -1) {
2756 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2757 }
2758 }
2759 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002760 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2761 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2762 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2763 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002764 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2765 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2766 } else {
2767 p.writeInt32(INT_MAX);
2768 }
Wink Savillec0114b32011-02-18 10:14:07 -08002769 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002770 p.writeInt32(99);
2771 p.writeInt32(INT_MAX);
2772 p.writeInt32(INT_MAX);
2773 p.writeInt32(INT_MAX);
2774 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002775 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002776 }
johnwangfdf825f2009-05-22 15:50:34 -07002777
2778 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002779 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002780 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2781 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2782 EVDO_SS.signalNoiseRatio=%d,\
2783 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002784 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002785 printBuf,
2786 p_cur->GW_SignalStrength.signalStrength,
2787 p_cur->GW_SignalStrength.bitErrorRate,
2788 p_cur->CDMA_SignalStrength.dbm,
2789 p_cur->CDMA_SignalStrength.ecio,
2790 p_cur->EVDO_SignalStrength.dbm,
2791 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002792 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2793 p_cur->LTE_SignalStrength.signalStrength,
2794 p_cur->LTE_SignalStrength.rsrp,
2795 p_cur->LTE_SignalStrength.rsrq,
2796 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002797 p_cur->LTE_SignalStrength.cqi,
2798 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002799 closeResponse;
2800
Wink Saville3d54e742009-05-18 18:00:44 -07002801 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002802 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002803 return RIL_ERRNO_INVALID_RESPONSE;
2804 }
2805
Wink Saville3d54e742009-05-18 18:00:44 -07002806 return 0;
2807}
2808
2809static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2810 if ((response == NULL) || (responselen == 0)) {
2811 return responseVoid(p, response, responselen);
2812 } else {
2813 return responseCdmaSignalInfoRecord(p, response, responselen);
2814 }
2815}
2816
2817static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2818 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002819 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002820 return RIL_ERRNO_INVALID_RESPONSE;
2821 }
2822
2823 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002824 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002825 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2826 return RIL_ERRNO_INVALID_RESPONSE;
2827 }
2828
2829 startResponse;
2830
2831 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2832 marshallSignalInfoRecord(p, *p_cur);
2833
2834 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2835 signal=%d]",
2836 printBuf,
2837 p_cur->isPresent,
2838 p_cur->signalType,
2839 p_cur->alertPitch,
2840 p_cur->signal);
2841
2842 closeResponse;
2843 return 0;
2844}
2845
Wink Savillea592eeb2009-05-22 13:26:36 -07002846static int responseCdmaCallWaiting(Parcel &p, void *response,
2847 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002848 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002849 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002850 return RIL_ERRNO_INVALID_RESPONSE;
2851 }
2852
Wink Savillec0114b32011-02-18 10:14:07 -08002853 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002854 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002855 }
2856
2857 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2858
2859 writeStringToParcel(p, p_cur->number);
2860 p.writeInt32(p_cur->numberPresentation);
2861 writeStringToParcel(p, p_cur->name);
2862 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2863
2864 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2865 p.writeInt32(p_cur->number_type);
2866 p.writeInt32(p_cur->number_plan);
2867 } else {
2868 p.writeInt32(0);
2869 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002870 }
2871
2872 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002873 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2874 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002875 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002876 printBuf,
2877 p_cur->number,
2878 p_cur->numberPresentation,
2879 p_cur->name,
2880 p_cur->signalInfoRecord.isPresent,
2881 p_cur->signalInfoRecord.signalType,
2882 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002883 p_cur->signalInfoRecord.signal,
2884 p_cur->number_type,
2885 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002886 closeResponse;
2887
2888 return 0;
2889}
2890
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002891static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2892 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002893 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002894 return RIL_ERRNO_INVALID_RESPONSE;
2895 }
2896
2897 startResponse;
2898 if (s_callbacks.version == 7) {
2899 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2900 p.writeInt32(p_cur->result);
2901 p.writeInt32(p_cur->ef_id);
2902 writeStringToParcel(p, p_cur->aid);
2903
2904 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2905 printBuf,
2906 p_cur->result,
2907 p_cur->ef_id,
2908 p_cur->aid);
2909 } else {
2910 int *p_cur = ((int *) response);
2911 p.writeInt32(p_cur[0]);
2912 p.writeInt32(p_cur[1]);
2913 writeStringToParcel(p, NULL);
2914
2915 appendPrintBuf("%sresult=%d, ef_id=%d",
2916 printBuf,
2917 p_cur[0],
2918 p_cur[1]);
2919 }
2920 closeResponse;
2921
2922 return 0;
2923}
2924
Wink Saville8a9e0212013-04-09 12:11:38 -07002925static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2926{
2927 if (response == NULL && responselen != 0) {
2928 RLOGE("invalid response: NULL");
2929 return RIL_ERRNO_INVALID_RESPONSE;
2930 }
2931
2932 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002933 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07002934 (int)responselen, (int)sizeof(RIL_CellInfo));
2935 return RIL_ERRNO_INVALID_RESPONSE;
2936 }
2937
2938 int num = responselen / sizeof(RIL_CellInfo);
2939 p.writeInt32(num);
2940
2941 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2942 startResponse;
2943 int i;
2944 for (i = 0; i < num; i++) {
2945 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2946 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2947 p.writeInt32((int)p_cur->cellInfoType);
2948 p.writeInt32(p_cur->registered);
2949 p.writeInt32(p_cur->timeStampType);
2950 p.writeInt64(p_cur->timeStamp);
2951 switch(p_cur->cellInfoType) {
2952 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07002953 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002954 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2955 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2956 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07002957 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2958 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002959 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2960 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2961
2962 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2963 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2964 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2965 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07002966 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2967 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2968 break;
2969 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07002970 case RIL_CELL_INFO_TYPE_WCDMA: {
2971 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2972 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2973 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2974 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2975 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2976 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2977 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2978 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2979 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2980
2981 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2982 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2983 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2984 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2985 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2986 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2987 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2988 break;
2989 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002990 case RIL_CELL_INFO_TYPE_CDMA: {
2991 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2992 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2993 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2994 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2995 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2996 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2997
2998 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2999 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3000 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3001 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3002 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3003
3004 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3005 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3006 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3007 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3008 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3009 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3010
3011 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3012 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3013 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3014 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3015 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3016 break;
3017 }
3018 case RIL_CELL_INFO_TYPE_LTE: {
3019 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3020 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3021 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3022 p_cur->CellInfo.lte.cellIdentityLte.ci,
3023 p_cur->CellInfo.lte.cellIdentityLte.pci,
3024 p_cur->CellInfo.lte.cellIdentityLte.tac);
3025
3026 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3027 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3028 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3029 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3030 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3031
3032 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3033 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3034 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3035 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3036 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3037 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3038 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3039 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3040 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3041 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3042 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3043 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3044 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3045 break;
3046 }
Etan Cohend3652192014-06-20 08:28:44 -07003047 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3048 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3049 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3050 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3051 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3052 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3053 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3054 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3055 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3056
3057 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3058 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3059 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3060 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3061 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3062 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3063 break;
3064 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003065 }
3066 p_cur += 1;
3067 }
3068 removeLastChar;
3069 closeResponse;
3070
3071 return 0;
3072}
3073
Etan Cohend3652192014-06-20 08:28:44 -07003074static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3075{
3076 if (response == NULL && responselen != 0) {
3077 RLOGE("invalid response: NULL");
3078 return RIL_ERRNO_INVALID_RESPONSE;
3079 }
3080
3081 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003082 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003083 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3084 return RIL_ERRNO_INVALID_RESPONSE;
3085 }
3086
3087 int num = responselen / sizeof(RIL_HardwareConfig);
3088 int i;
3089 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3090
3091 p.writeInt32(num);
3092
3093 startResponse;
3094 for (i = 0; i < num; i++) {
3095 switch (p_cur[i].type) {
3096 case RIL_HARDWARE_CONFIG_MODEM: {
3097 writeStringToParcel(p, p_cur[i].uuid);
3098 p.writeInt32((int)p_cur[i].state);
3099 p.writeInt32(p_cur[i].cfg.modem.rat);
3100 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3101 p.writeInt32(p_cur[i].cfg.modem.maxData);
3102 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3103
3104 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3105 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3106 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3107 break;
3108 }
3109 case RIL_HARDWARE_CONFIG_SIM: {
3110 writeStringToParcel(p, p_cur[i].uuid);
3111 p.writeInt32((int)p_cur[i].state);
3112 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3113
3114 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3115 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3116 break;
3117 }
3118 }
3119 }
3120 removeLastChar;
3121 closeResponse;
3122 return 0;
3123}
3124
Wink Saville3d54e742009-05-18 18:00:44 -07003125static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003126 int ret;
3127 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3128 /* trigger event loop to wakeup. No reason to do this,
3129 * if we're in the event loop thread */
3130 do {
3131 ret = write (s_fdWakeupWrite, " ", 1);
3132 } while (ret < 0 && errno == EINTR);
3133 }
3134}
3135
Wink Saville3d54e742009-05-18 18:00:44 -07003136static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003137 ril_event_add(ev);
3138 triggerEvLoop();
3139}
3140
Wink Savillefd729372011-02-22 16:19:39 -08003141static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3142 p.writeInt32(num_apps);
3143 startResponse;
3144 for (int i = 0; i < num_apps; i++) {
3145 p.writeInt32(appStatus[i].app_type);
3146 p.writeInt32(appStatus[i].app_state);
3147 p.writeInt32(appStatus[i].perso_substate);
3148 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3149 writeStringToParcel(p, (const char*)
3150 (appStatus[i].app_label_ptr));
3151 p.writeInt32(appStatus[i].pin1_replaced);
3152 p.writeInt32(appStatus[i].pin1);
3153 p.writeInt32(appStatus[i].pin2);
3154 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3155 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3156 printBuf,
3157 appStatus[i].app_type,
3158 appStatus[i].app_state,
3159 appStatus[i].perso_substate,
3160 appStatus[i].aid_ptr,
3161 appStatus[i].app_label_ptr,
3162 appStatus[i].pin1_replaced,
3163 appStatus[i].pin1,
3164 appStatus[i].pin2);
3165 }
3166 closeResponse;
3167}
3168
Wink Savillef4c4d362009-04-02 01:37:03 -07003169static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3170 int i;
3171
3172 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003173 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003174 return RIL_ERRNO_INVALID_RESPONSE;
3175 }
3176
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003177 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003178 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003179
Wink Savillefd729372011-02-22 16:19:39 -08003180 p.writeInt32(p_cur->card_state);
3181 p.writeInt32(p_cur->universal_pin_state);
3182 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3183 p.writeInt32(p_cur->cdma_subscription_app_index);
3184 p.writeInt32(p_cur->ims_subscription_app_index);
3185
3186 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003187 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003188 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3189
3190 p.writeInt32(p_cur->card_state);
3191 p.writeInt32(p_cur->universal_pin_state);
3192 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3193 p.writeInt32(p_cur->cdma_subscription_app_index);
3194 p.writeInt32(-1);
3195
3196 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003197 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003198 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003199 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003200 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003201
3202 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003203}
Wink Savillef4c4d362009-04-02 01:37:03 -07003204
Wink Savillea592eeb2009-05-22 13:26:36 -07003205static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3206 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003207 p.writeInt32(num);
3208
Wink Savillef4c4d362009-04-02 01:37:03 -07003209 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003210 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3211 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3212 for (int i = 0; i < num; i++) {
3213 p.writeInt32(p_cur[i]->fromServiceId);
3214 p.writeInt32(p_cur[i]->toServiceId);
3215 p.writeInt32(p_cur[i]->fromCodeScheme);
3216 p.writeInt32(p_cur[i]->toCodeScheme);
3217 p.writeInt32(p_cur[i]->selected);
3218
3219 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3220 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3221 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3222 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3223 p_cur[i]->selected);
3224 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003225 closeResponse;
3226
3227 return 0;
3228}
3229
Wink Savillea592eeb2009-05-22 13:26:36 -07003230static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3231 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3232 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003233
Wink Savillea592eeb2009-05-22 13:26:36 -07003234 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3235 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003236
3237 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003238 for (int i = 0 ; i < num ; i++ ) {
3239 p.writeInt32(p_cur[i]->service_category);
3240 p.writeInt32(p_cur[i]->language);
3241 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003242
Wink Savillea592eeb2009-05-22 13:26:36 -07003243 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3244 selected =%d], ",
3245 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3246 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003247 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003248 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003249
Wink Savillef4c4d362009-04-02 01:37:03 -07003250 return 0;
3251}
3252
3253static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3254 int num;
3255 int digitCount;
3256 int digitLimit;
3257 uint8_t uct;
3258 void* dest;
3259
Wink Saville8eb2a122012-11-19 16:05:13 -08003260 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003261
Wink Savillef4c4d362009-04-02 01:37:03 -07003262 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003263 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003264 return RIL_ERRNO_INVALID_RESPONSE;
3265 }
3266
Wink Savillef5903df2009-04-24 11:54:14 -07003267 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003268 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003269 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003270 return RIL_ERRNO_INVALID_RESPONSE;
3271 }
3272
3273 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3274 p.writeInt32(p_cur->uTeleserviceID);
3275 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3276 p.writeInt32(p_cur->uServicecategory);
3277 p.writeInt32(p_cur->sAddress.digit_mode);
3278 p.writeInt32(p_cur->sAddress.number_mode);
3279 p.writeInt32(p_cur->sAddress.number_type);
3280 p.writeInt32(p_cur->sAddress.number_plan);
3281 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3282 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3283 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3284 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3285 }
3286
3287 p.writeInt32(p_cur->sSubAddress.subaddressType);
3288 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3289 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3290 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3291 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3292 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3293 }
3294
3295 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3296 p.writeInt32(p_cur->uBearerDataLen);
3297 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3298 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3299 }
3300
3301 startResponse;
3302 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003303 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003304 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3305 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3306 closeResponse;
3307
3308 return 0;
3309}
3310
Wink Savillec29360a2014-07-13 05:17:28 -07003311static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3312{
3313 int num = responselen / sizeof(RIL_DcRtInfo);
3314 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003315 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003316 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3317 return RIL_ERRNO_INVALID_RESPONSE;
3318 }
3319
3320 startResponse;
3321 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3322 p.writeInt64(pDcRtInfo->time);
3323 p.writeInt32(pDcRtInfo->powerState);
3324 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3325 pDcRtInfo->time,
3326 pDcRtInfo->powerState);
3327 closeResponse;
3328
3329 return 0;
3330}
3331
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003332/**
3333 * A write on the wakeup fd is done just to pop us out of select()
3334 * We empty the buffer here and then ril_event will reset the timers on the
3335 * way back down
3336 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003337static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003338 char buff[16];
3339 int ret;
3340
Wink Saville8eb2a122012-11-19 16:05:13 -08003341 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003342
3343 /* empty our wakeup socket out */
3344 do {
3345 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003346 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003347}
3348
Etan Cohend3652192014-06-20 08:28:44 -07003349static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003350 int ret;
3351 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003352 /* Hook for current context
3353 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3354 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3355 /* pendingRequestsHook refer to &s_pendingRequests */
3356 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003357
Etan Cohend3652192014-06-20 08:28:44 -07003358#if (SIM_COUNT >= 2)
3359 if (socket_id == RIL_SOCKET_2) {
3360 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3361 pendingRequestsHook = &s_pendingRequests_socket2;
3362 }
3363#if (SIM_COUNT >= 3)
3364 else if (socket_id == RIL_SOCKET_3) {
3365 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3366 pendingRequestsHook = &s_pendingRequests_socket3;
3367 }
3368#endif
3369#if (SIM_COUNT >= 4)
3370 else if (socket_id == RIL_SOCKET_4) {
3371 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3372 pendingRequestsHook = &s_pendingRequests_socket4;
3373 }
3374#endif
3375#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003376 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003377 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003378 assert (ret == 0);
3379
Etan Cohend3652192014-06-20 08:28:44 -07003380 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003381
Etan Cohend3652192014-06-20 08:28:44 -07003382 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003383 ; p_cur != NULL
3384 ; p_cur = p_cur->p_next
3385 ) {
3386 p_cur->cancelled = 1;
3387 }
3388
Etan Cohend3652192014-06-20 08:28:44 -07003389 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003390 assert (ret == 0);
3391}
3392
Wink Savillef4c4d362009-04-02 01:37:03 -07003393static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003394 RecordStream *p_rs;
3395 void *p_record;
3396 size_t recordlen;
3397 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003398 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003399
Etan Cohend3652192014-06-20 08:28:44 -07003400 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003401
Etan Cohend3652192014-06-20 08:28:44 -07003402 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003403
3404 for (;;) {
3405 /* loop until EAGAIN/EINTR, end of stream, or other error */
3406 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3407
3408 if (ret == 0 && p_record == NULL) {
3409 /* end-of-stream */
3410 break;
3411 } else if (ret < 0) {
3412 break;
3413 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003414 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003415 }
3416 }
3417
3418 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3419 /* fatal error or end-of-stream */
3420 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003421 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003422 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003423 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003424 }
Wink Saville7f856802009-06-09 10:23:37 -07003425
Etan Cohend3652192014-06-20 08:28:44 -07003426 close(fd);
3427 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003428
Etan Cohend3652192014-06-20 08:28:44 -07003429 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003430
3431 record_stream_free(p_rs);
3432
3433 /* start listening for new connections again */
3434 rilEventAddWakeup(&s_listen_event);
3435
Etan Cohend3652192014-06-20 08:28:44 -07003436 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003437 }
3438}
3439
3440
Etan Cohend3652192014-06-20 08:28:44 -07003441static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003442 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003443 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003444 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3445 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003446
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003447 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003448 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3449 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003450
3451 // Send last NITZ time data, in case it was missed
3452 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003453 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003454
3455 free(s_lastNITZTimeData);
3456 s_lastNITZTimeData = NULL;
3457 }
3458
3459 // Get version string
3460 if (s_callbacks.getVersion != NULL) {
3461 const char *version;
3462 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003463 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003464
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003465 property_set(PROPERTY_RIL_IMPL, version);
3466 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003467 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003468 property_set(PROPERTY_RIL_IMPL, "unavailable");
3469 }
3470
3471}
3472
Wink Savillef4c4d362009-04-02 01:37:03 -07003473static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003474 int ret;
3475 int err;
3476 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003477 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003478 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003479 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003480
3481 struct sockaddr_un peeraddr;
3482 socklen_t socklen = sizeof (peeraddr);
3483
3484 struct ucred creds;
3485 socklen_t szCreds = sizeof(creds);
3486
3487 struct passwd *pwd = NULL;
3488
Etan Cohend3652192014-06-20 08:28:44 -07003489 assert (*p_info->fdCommand < 0);
3490 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003491
Etan Cohend3652192014-06-20 08:28:44 -07003492 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003493
Etan Cohend3652192014-06-20 08:28:44 -07003494 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003495 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003496 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003497 rilEventAddWakeup(p_info->listen_event);
3498 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003499 }
3500
3501 /* check the credential of the other side and only accept socket from
3502 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003503 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003504 errno = 0;
3505 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003506
Etan Cohend3652192014-06-20 08:28:44 -07003507 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003508
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003509 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003510 errno = 0;
3511 pwd = getpwuid(creds.uid);
3512 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003513 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003514 is_phone_socket = 1;
3515 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003516 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003517 }
3518 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003519 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003520 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003521 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003522 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003523 }
3524
Etan Cohend3652192014-06-20 08:28:44 -07003525 if (!is_phone_socket) {
3526 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003527
Etan Cohend3652192014-06-20 08:28:44 -07003528 close(fdCommand);
3529 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003530
Etan Cohend3652192014-06-20 08:28:44 -07003531 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003532
3533 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003534 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003535
3536 return;
3537 }
3538
Etan Cohend3652192014-06-20 08:28:44 -07003539 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003540
3541 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003542 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003543 }
3544
Etan Cohend3652192014-06-20 08:28:44 -07003545 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003546
Etan Cohend3652192014-06-20 08:28:44 -07003547 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003548
Etan Cohend3652192014-06-20 08:28:44 -07003549 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003550
Etan Cohend3652192014-06-20 08:28:44 -07003551 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003552
Etan Cohend3652192014-06-20 08:28:44 -07003553 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3554 p_info->processCommandsCallback, p_info);
3555
3556 rilEventAddWakeup (p_info->commands_event);
3557
3558 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003559}
3560
3561static void freeDebugCallbackArgs(int number, char **args) {
3562 for (int i = 0; i < number; i++) {
3563 if (args[i] != NULL) {
3564 free(args[i]);
3565 }
3566 }
3567 free(args);
3568}
3569
Wink Savillef4c4d362009-04-02 01:37:03 -07003570static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003571 int acceptFD, option;
3572 struct sockaddr_un peeraddr;
3573 socklen_t socklen = sizeof (peeraddr);
3574 int data;
3575 unsigned int qxdm_data[6];
3576 const char *deactData[1] = {"1"};
3577 char *actData[1];
3578 RIL_Dial dialData;
3579 int hangupData[1] = {1};
3580 int number;
3581 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003582 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3583 int sim_id = 0;
3584
3585 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003586
3587 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3588
3589 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003590 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003591 return;
3592 }
3593
3594 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003595 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003596 return;
3597 }
3598 args = (char **) malloc(sizeof(char*) * number);
3599
3600 for (int i = 0; i < number; i++) {
3601 int len;
3602 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003603 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003604 freeDebugCallbackArgs(i, args);
3605 return;
3606 }
3607 // +1 for null-term
3608 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003609 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003610 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003611 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003612 freeDebugCallbackArgs(i, args);
3613 return;
3614 }
3615 char * buf = args[i];
3616 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003617 if ((i+1) == number) {
3618 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3619 sim_id = atoi(args[i]);
3620 switch (sim_id) {
3621 case 0:
3622 socket_id = RIL_SOCKET_1;
3623 break;
3624 #if (SIM_COUNT >= 2)
3625 case 1:
3626 socket_id = RIL_SOCKET_2;
3627 break;
3628 #endif
3629 #if (SIM_COUNT >= 3)
3630 case 2:
3631 socket_id = RIL_SOCKET_3;
3632 break;
3633 #endif
3634 #if (SIM_COUNT >= 4)
3635 case 3:
3636 socket_id = RIL_SOCKET_4;
3637 break;
3638 #endif
3639 default:
3640 socket_id = RIL_SOCKET_1;
3641 break;
3642 }
3643 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003644 }
3645
3646 switch (atoi(args[0])) {
3647 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003648 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003649 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003650 break;
3651 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003652 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003653 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003654 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003655 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003656 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3657 close(s_ril_param_socket.fdCommand);
3658 s_ril_param_socket.fdCommand = -1;
3659 }
3660 #if (SIM_COUNT == 2)
3661 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3662 close(s_ril_param_socket2.fdCommand);
3663 s_ril_param_socket2.fdCommand = -1;
3664 }
3665 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003666 break;
3667 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003668 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003669 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003670 break;
3671 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003672 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003673 qxdm_data[0] = 65536; // head.func_tag
3674 qxdm_data[1] = 16; // head.len
3675 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3676 qxdm_data[3] = 32; // log_file_size: 32megabytes
3677 qxdm_data[4] = 0; // log_mask
3678 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003679 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003680 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003681 break;
3682 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003683 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003684 qxdm_data[0] = 65536;
3685 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003686 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003687 qxdm_data[3] = 32;
3688 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003689 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003690 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003691 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003692 break;
3693 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003694 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003695 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003696 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003697 sleep(2);
3698 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003699 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003700 break;
3701 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003702 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003703 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003704 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003705 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003706 break;
3707 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003708 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003709 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003710 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003711 break;
3712 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003713 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003714 dialData.clir = 0;
3715 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003716 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003717 break;
3718 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003719 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003720 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003721 break;
3722 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003723 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003724 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003725 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003726 break;
3727 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003728 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003729 break;
3730 }
3731 freeDebugCallbackArgs(number, args);
3732 close(acceptFD);
3733}
3734
3735
Wink Savillef4c4d362009-04-02 01:37:03 -07003736static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003737 UserCallbackInfo *p_info;
3738
3739 p_info = (UserCallbackInfo *)param;
3740
3741 p_info->p_callback(p_info->userParam);
3742
3743
3744 // FIXME generalize this...there should be a cancel mechanism
3745 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3746 s_last_wake_timeout_info = NULL;
3747 }
3748
3749 free(p_info);
3750}
3751
3752
3753static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003754eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003755 int ret;
3756 int filedes[2];
3757
3758 ril_event_init();
3759
3760 pthread_mutex_lock(&s_startupMutex);
3761
3762 s_started = 1;
3763 pthread_cond_broadcast(&s_startupCond);
3764
3765 pthread_mutex_unlock(&s_startupMutex);
3766
3767 ret = pipe(filedes);
3768
3769 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003770 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003771 return NULL;
3772 }
3773
3774 s_fdWakeupRead = filedes[0];
3775 s_fdWakeupWrite = filedes[1];
3776
3777 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3778
3779 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3780 processWakeupCallback, NULL);
3781
3782 rilEventAddWakeup (&s_wakeupfd_event);
3783
3784 // Only returns on error
3785 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003786 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003787 // kill self to restart on error
3788 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003789
3790 return NULL;
3791}
3792
Wink Saville7f856802009-06-09 10:23:37 -07003793extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003794RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003795 /* spin up eventLoop thread and wait for it to get started */
3796 s_started = 0;
3797 pthread_mutex_lock(&s_startupMutex);
3798
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003799 pthread_attr_t attr;
3800 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003801 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003802
Elliott Hughesfd81e712014-01-06 12:46:02 -08003803 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3804 if (result != 0) {
3805 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003806 goto done;
3807 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003808
3809 while (s_started == 0) {
3810 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3811 }
3812
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003813done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003814 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003815}
3816
3817// Used for testing purpose only.
3818extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3819 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3820}
3821
Etan Cohend3652192014-06-20 08:28:44 -07003822static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3823 int fdListen = -1;
3824 int ret;
3825 char socket_name[10];
3826
3827 memset(socket_name, 0, sizeof(char)*10);
3828
3829 switch(socket_id) {
3830 case RIL_SOCKET_1:
3831 strncpy(socket_name, RIL_getRilSocketName(), 9);
3832 break;
3833 #if (SIM_COUNT >= 2)
3834 case RIL_SOCKET_2:
3835 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3836 break;
3837 #endif
3838 #if (SIM_COUNT >= 3)
3839 case RIL_SOCKET_3:
3840 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3841 break;
3842 #endif
3843 #if (SIM_COUNT >= 4)
3844 case RIL_SOCKET_4:
3845 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3846 break;
3847 #endif
3848 default:
3849 RLOGE("Socket id is wrong!!");
3850 return;
3851 }
3852
3853 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3854
3855 fdListen = android_get_control_socket(socket_name);
3856 if (fdListen < 0) {
3857 RLOGE("Failed to get socket %s", socket_name);
3858 exit(-1);
3859 }
3860
3861 ret = listen(fdListen, 4);
3862
3863 if (ret < 0) {
3864 RLOGE("Failed to listen on control socket '%d': %s",
3865 fdListen, strerror(errno));
3866 exit(-1);
3867 }
3868 socket_listen_p->fdListen = fdListen;
3869
3870 /* note: non-persistent so we can accept only one connection at a time */
3871 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3872 listenCallback, socket_listen_p);
3873
3874 rilEventAddWakeup (socket_listen_p->listen_event);
3875}
3876
Wink Saville7f856802009-06-09 10:23:37 -07003877extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003878RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003879 int ret;
3880 int flags;
3881
Etan Cohend3652192014-06-20 08:28:44 -07003882 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3883
Wink Saville43808972011-01-13 17:39:51 -08003884 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003885 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003886 return;
3887 }
Wink Saville43808972011-01-13 17:39:51 -08003888 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003889 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003890 callbacks->version, RIL_VERSION_MIN);
3891 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07003892 }
Wink Saville43808972011-01-13 17:39:51 -08003893 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003894 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003895 callbacks->version, RIL_VERSION);
3896 return;
3897 }
Wink Saville8eb2a122012-11-19 16:05:13 -08003898 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003899
3900 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003901 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003902 "Subsequent call ignored");
3903 return;
3904 }
3905
3906 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3907
Etan Cohend3652192014-06-20 08:28:44 -07003908 /* Initialize socket1 parameters */
3909 s_ril_param_socket = {
3910 RIL_SOCKET_1, /* socket_id */
3911 -1, /* fdListen */
3912 -1, /* fdCommand */
3913 PHONE_PROCESS, /* processName */
3914 &s_commands_event, /* commands_event */
3915 &s_listen_event, /* listen_event */
3916 processCommandsCallback, /* processCommandsCallback */
3917 NULL /* p_rs */
3918 };
3919
3920#if (SIM_COUNT >= 2)
3921 s_ril_param_socket2 = {
3922 RIL_SOCKET_2, /* socket_id */
3923 -1, /* fdListen */
3924 -1, /* fdCommand */
3925 PHONE_PROCESS, /* processName */
3926 &s_commands_event_socket2, /* commands_event */
3927 &s_listen_event_socket2, /* listen_event */
3928 processCommandsCallback, /* processCommandsCallback */
3929 NULL /* p_rs */
3930 };
3931#endif
3932
3933#if (SIM_COUNT >= 3)
3934 s_ril_param_socket3 = {
3935 RIL_SOCKET_3, /* socket_id */
3936 -1, /* fdListen */
3937 -1, /* fdCommand */
3938 PHONE_PROCESS, /* processName */
3939 &s_commands_event_socket3, /* commands_event */
3940 &s_listen_event_socket3, /* listen_event */
3941 processCommandsCallback, /* processCommandsCallback */
3942 NULL /* p_rs */
3943 };
3944#endif
3945
3946#if (SIM_COUNT >= 4)
3947 s_ril_param_socket4 = {
3948 RIL_SOCKET_4, /* socket_id */
3949 -1, /* fdListen */
3950 -1, /* fdCommand */
3951 PHONE_PROCESS, /* processName */
3952 &s_commands_event_socket4, /* commands_event */
3953 &s_listen_event_socket4, /* listen_event */
3954 processCommandsCallback, /* processCommandsCallback */
3955 NULL /* p_rs */
3956 };
3957#endif
3958
3959
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003960 s_registerCalled = 1;
3961
Etan Cohend3652192014-06-20 08:28:44 -07003962 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003963 // Little self-check
3964
Wink Savillef4c4d362009-04-02 01:37:03 -07003965 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003966 assert(i == s_commands[i].requestNumber);
3967 }
3968
Wink Savillef4c4d362009-04-02 01:37:03 -07003969 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07003970 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003971 == s_unsolResponses[i].requestNumber);
3972 }
3973
3974 // New rild impl calls RIL_startEventLoop() first
3975 // old standalone impl wants it here.
3976
3977 if (s_started == 0) {
3978 RIL_startEventLoop();
3979 }
3980
Etan Cohend3652192014-06-20 08:28:44 -07003981 // start listen socket1
3982 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003983
Etan Cohend3652192014-06-20 08:28:44 -07003984#if (SIM_COUNT >= 2)
3985 // start listen socket2
3986 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
3987#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003988
Etan Cohend3652192014-06-20 08:28:44 -07003989#if (SIM_COUNT >= 3)
3990 // start listen socket3
3991 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
3992#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003993
Etan Cohend3652192014-06-20 08:28:44 -07003994#if (SIM_COUNT >= 4)
3995 // start listen socket4
3996 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
3997#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003998
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003999
4000#if 1
4001 // start debug interface socket
4002
Etan Cohend3652192014-06-20 08:28:44 -07004003 char *inst = NULL;
4004 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4005 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4006 }
4007
4008 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4009 if (inst != NULL) {
4010 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4011 }
4012
4013 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004014 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004015 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004016 exit(-1);
4017 }
4018
4019 ret = listen(s_fdDebug, 4);
4020
4021 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004022 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004023 s_fdDebug, strerror(errno));
4024 exit(-1);
4025 }
4026
4027 ril_event_set (&s_debug_event, s_fdDebug, true,
4028 debugCallback, NULL);
4029
4030 rilEventAddWakeup (&s_debug_event);
4031#endif
4032
4033}
4034
4035static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004036checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004037 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004038 /* Hook for current context
4039 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4040 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4041 /* pendingRequestsHook refer to &s_pendingRequests */
4042 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004043
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004044 if (pRI == NULL) {
4045 return 0;
4046 }
4047
Etan Cohend3652192014-06-20 08:28:44 -07004048#if (SIM_COUNT >= 2)
4049 if (pRI->socket_id == RIL_SOCKET_2) {
4050 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4051 pendingRequestsHook = &s_pendingRequests_socket2;
4052 }
4053#if (SIM_COUNT >= 3)
4054 if (pRI->socket_id == RIL_SOCKET_3) {
4055 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4056 pendingRequestsHook = &s_pendingRequests_socket3;
4057 }
4058#endif
4059#if (SIM_COUNT >= 4)
4060 if (pRI->socket_id == RIL_SOCKET_4) {
4061 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4062 pendingRequestsHook = &s_pendingRequests_socket4;
4063 }
4064#endif
4065#endif
4066 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004067
Etan Cohend3652192014-06-20 08:28:44 -07004068 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004069 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004070 ; ppCur = &((*ppCur)->p_next)
4071 ) {
4072 if (pRI == *ppCur) {
4073 ret = 1;
4074
4075 *ppCur = (*ppCur)->p_next;
4076 break;
4077 }
4078 }
4079
Etan Cohend3652192014-06-20 08:28:44 -07004080 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004081
4082 return ret;
4083}
4084
4085
4086extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004087RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004088 RequestInfo *pRI;
4089 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004090 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004091 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004092 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004093
4094 pRI = (RequestInfo *)t;
4095
Jayachandran C6c607592014-08-04 15:48:01 -07004096 if (!checkAndDequeueRequestInfo(pRI)) {
4097 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4098 return;
4099 }
4100
Etan Cohend3652192014-06-20 08:28:44 -07004101 socket_id = pRI->socket_id;
4102#if (SIM_COUNT >= 2)
4103 if (socket_id == RIL_SOCKET_2) {
4104 fd = s_ril_param_socket2.fdCommand;
4105 }
4106#if (SIM_COUNT >= 3)
4107 if (socket_id == RIL_SOCKET_3) {
4108 fd = s_ril_param_socket3.fdCommand;
4109 }
4110#endif
4111#if (SIM_COUNT >= 4)
4112 if (socket_id == RIL_SOCKET_4) {
4113 fd = s_ril_param_socket4.fdCommand;
4114 }
4115#endif
4116#endif
4117 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4118
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004119 if (pRI->local > 0) {
4120 // Locally issued command...void only!
4121 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004122 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004123
4124 goto done;
4125 }
4126
4127 appendPrintBuf("[%04d]< %s",
4128 pRI->token, requestToString(pRI->pCI->requestNumber));
4129
4130 if (pRI->cancelled == 0) {
4131 Parcel p;
4132
4133 p.writeInt32 (RESPONSE_SOLICITED);
4134 p.writeInt32 (pRI->token);
4135 errorOffset = p.dataPosition();
4136
4137 p.writeInt32 (e);
4138
johnwangb2a61842009-06-02 14:55:45 -07004139 if (response != NULL) {
4140 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004141 ret = pRI->pCI->responseFunction(p, response, responselen);
4142
4143 /* if an error occurred, rewind and mark it */
4144 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004145 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004146 p.setDataPosition(errorOffset);
4147 p.writeInt32 (ret);
4148 }
johnwangb2a61842009-06-02 14:55:45 -07004149 }
4150
4151 if (e != RIL_E_SUCCESS) {
4152 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004153 }
4154
Etan Cohend3652192014-06-20 08:28:44 -07004155 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004156 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004157 }
Etan Cohend3652192014-06-20 08:28:44 -07004158 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004159 }
4160
4161done:
4162 free(pRI);
4163}
4164
4165
4166static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004167grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004168 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4169}
4170
4171static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004172releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004173 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4174}
4175
4176/**
4177 * Timer callback to put us back to sleep before the default timeout
4178 */
4179static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004180wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004181 // We're using "param != NULL" as a cancellation mechanism
4182 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004183 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004184
4185 releaseWakeLock();
4186 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004187 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004188 }
4189}
4190
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004191static int
4192decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4193 switch (radioState) {
4194 case RADIO_STATE_SIM_NOT_READY:
4195 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4196 case RADIO_STATE_SIM_READY:
4197 return RADIO_TECH_UMTS;
4198
4199 case RADIO_STATE_RUIM_NOT_READY:
4200 case RADIO_STATE_RUIM_READY:
4201 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4202 case RADIO_STATE_NV_NOT_READY:
4203 case RADIO_STATE_NV_READY:
4204 return RADIO_TECH_1xRTT;
4205
4206 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004207 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004208 return -1;
4209 }
4210}
4211
4212static int
4213decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4214 switch (radioState) {
4215 case RADIO_STATE_SIM_NOT_READY:
4216 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4217 case RADIO_STATE_SIM_READY:
4218 case RADIO_STATE_RUIM_NOT_READY:
4219 case RADIO_STATE_RUIM_READY:
4220 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4221 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4222
4223 case RADIO_STATE_NV_NOT_READY:
4224 case RADIO_STATE_NV_READY:
4225 return CDMA_SUBSCRIPTION_SOURCE_NV;
4226
4227 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004228 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004229 return -1;
4230 }
4231}
4232
4233static int
4234decodeSimStatus (RIL_RadioState radioState) {
4235 switch (radioState) {
4236 case RADIO_STATE_SIM_NOT_READY:
4237 case RADIO_STATE_RUIM_NOT_READY:
4238 case RADIO_STATE_NV_NOT_READY:
4239 case RADIO_STATE_NV_READY:
4240 return -1;
4241 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4242 case RADIO_STATE_SIM_READY:
4243 case RADIO_STATE_RUIM_READY:
4244 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4245 return radioState;
4246 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004247 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004248 return -1;
4249 }
4250}
4251
4252static bool is3gpp2(int radioTech) {
4253 switch (radioTech) {
4254 case RADIO_TECH_IS95A:
4255 case RADIO_TECH_IS95B:
4256 case RADIO_TECH_1xRTT:
4257 case RADIO_TECH_EVDO_0:
4258 case RADIO_TECH_EVDO_A:
4259 case RADIO_TECH_EVDO_B:
4260 case RADIO_TECH_EHRPD:
4261 return true;
4262 default:
4263 return false;
4264 }
4265}
4266
4267/* If RIL sends SIM states or RUIM states, store the voice radio
4268 * technology and subscription source information so that they can be
4269 * returned when telephony framework requests them
4270 */
4271static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004272processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004273
4274 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4275 int newVoiceRadioTech;
4276 int newCdmaSubscriptionSource;
4277 int newSimStatus;
4278
4279 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4280 from Radio State and send change notifications if there has been a change */
4281 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4282 if(newVoiceRadioTech != voiceRadioTech) {
4283 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004284 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4285 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004286 }
4287 if(is3gpp2(newVoiceRadioTech)) {
4288 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4289 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4290 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004291 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4292 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004293 }
4294 }
4295 newSimStatus = decodeSimStatus(newRadioState);
4296 if(newSimStatus != simRuimStatus) {
4297 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004298 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004299 }
4300
4301 /* Send RADIO_ON to telephony */
4302 newRadioState = RADIO_STATE_ON;
4303 }
4304
4305 return newRadioState;
4306}
4307
Etan Cohend3652192014-06-20 08:28:44 -07004308
4309#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004310extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004311void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4312 size_t datalen, RIL_SOCKET_ID socket_id)
4313#else
4314extern "C"
4315void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004316 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004317#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004318{
4319 int unsolResponseIndex;
4320 int ret;
4321 int64_t timeReceived = 0;
4322 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004323 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004324 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4325
4326#if defined(ANDROID_MULTI_SIM)
4327 soc_id = socket_id;
4328#endif
4329
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004330
4331 if (s_registerCalled == 0) {
4332 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004333 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004334 return;
4335 }
Wink Saville7f856802009-06-09 10:23:37 -07004336
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004337 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4338
4339 if ((unsolResponseIndex < 0)
4340 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004341 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004342 return;
4343 }
4344
4345 // Grab a wake lock if needed for this reponse,
4346 // as we exit we'll either release it immediately
4347 // or set a timer to release it later.
4348 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4349 case WAKE_PARTIAL:
4350 grabPartialWakeLock();
4351 shouldScheduleTimeout = true;
4352 break;
4353
4354 case DONT_WAKE:
4355 default:
4356 // No wake lock is grabed so don't set timeout
4357 shouldScheduleTimeout = false;
4358 break;
4359 }
4360
4361 // Mark the time this was received, doing this
4362 // after grabing the wakelock incase getting
4363 // the elapsedRealTime might cause us to goto
4364 // sleep.
4365 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4366 timeReceived = elapsedRealtime();
4367 }
4368
4369 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4370
4371 Parcel p;
4372
4373 p.writeInt32 (RESPONSE_UNSOLICITED);
4374 p.writeInt32 (unsolResponse);
4375
4376 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004377 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004378 if (ret != 0) {
4379 // Problem with the response. Don't continue;
4380 goto error_exit;
4381 }
4382
4383 // some things get more payload
4384 switch(unsolResponse) {
4385 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004386 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004387 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004388 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004389 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004390 break;
4391
4392
4393 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4394 // Store the time that this was received so the
4395 // handler of this message can account for
4396 // the time it takes to arrive and process. In
4397 // particular the system has been known to sleep
4398 // before this message can be processed.
4399 p.writeInt64(timeReceived);
4400 break;
4401 }
4402
Etan Cohend3652192014-06-20 08:28:44 -07004403 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4404 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004405 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4406
4407 // Unfortunately, NITZ time is not poll/update like everything
4408 // else in the system. So, if the upstream client isn't connected,
4409 // keep a copy of the last NITZ response (with receive time noted
4410 // above) around so we can deliver it when it is connected
4411
4412 if (s_lastNITZTimeData != NULL) {
4413 free (s_lastNITZTimeData);
4414 s_lastNITZTimeData = NULL;
4415 }
4416
4417 s_lastNITZTimeData = malloc(p.dataSize());
4418 s_lastNITZTimeDataSize = p.dataSize();
4419 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4420 }
4421
4422 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4423 // FIXME The java code should handshake here to release wake lock
4424
4425 if (shouldScheduleTimeout) {
4426 // Cancel the previous request
4427 if (s_last_wake_timeout_info != NULL) {
4428 s_last_wake_timeout_info->userParam = (void *)1;
4429 }
4430
4431 s_last_wake_timeout_info
4432 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4433 &TIMEVAL_WAKE_TIMEOUT);
4434 }
4435
4436 // Normal exit
4437 return;
4438
4439error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004440 if (shouldScheduleTimeout) {
4441 releaseWakeLock();
4442 }
4443}
4444
Wink Saville7f856802009-06-09 10:23:37 -07004445/** FIXME generalize this if you track UserCAllbackInfo, clear it
4446 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004447*/
4448static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004449internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004450 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004451{
4452 struct timeval myRelativeTime;
4453 UserCallbackInfo *p_info;
4454
4455 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4456
Wink Saville7f856802009-06-09 10:23:37 -07004457 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004458 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004459
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004460 if (relativeTime == NULL) {
4461 /* treat null parameter as a 0 relative time */
4462 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4463 } else {
4464 /* FIXME I think event_add's tv param is really const anyway */
4465 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4466 }
4467
4468 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4469
4470 ril_timer_add(&(p_info->event), &myRelativeTime);
4471
4472 triggerEvLoop();
4473 return p_info;
4474}
4475
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004476
4477extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004478RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4479 const struct timeval *relativeTime) {
4480 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004481}
4482
4483const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004484failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004485 switch(e) {
4486 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004487 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004488 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4489 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4490 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4491 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4492 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4493 case RIL_E_CANCELLED: return "E_CANCELLED";
4494 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4495 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4496 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004497 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004498 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004499#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004500 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4501 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4502#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004503 default: return "<unknown error>";
4504 }
4505}
4506
4507const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004508radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004509 switch(s) {
4510 case RADIO_STATE_OFF: return "RADIO_OFF";
4511 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4512 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4513 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4514 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004515 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4516 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4517 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4518 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4519 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004520 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004521 default: return "<unknown state>";
4522 }
4523}
4524
4525const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004526callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004527 switch(s) {
4528 case RIL_CALL_ACTIVE : return "ACTIVE";
4529 case RIL_CALL_HOLDING: return "HOLDING";
4530 case RIL_CALL_DIALING: return "DIALING";
4531 case RIL_CALL_ALERTING: return "ALERTING";
4532 case RIL_CALL_INCOMING: return "INCOMING";
4533 case RIL_CALL_WAITING: return "WAITING";
4534 default: return "<unknown state>";
4535 }
4536}
4537
4538const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004539requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004540/*
4541 cat libs/telephony/ril_commands.h \
4542 | egrep "^ *{RIL_" \
4543 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4544
4545
4546 cat libs/telephony/ril_unsol_commands.h \
4547 | egrep "^ *{RIL_" \
4548 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4549
4550*/
4551 switch(request) {
4552 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4553 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4554 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4555 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4556 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4557 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4558 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4559 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4560 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4561 case RIL_REQUEST_DIAL: return "DIAL";
4562 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4563 case RIL_REQUEST_HANGUP: return "HANGUP";
4564 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4565 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4566 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4567 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4568 case RIL_REQUEST_UDUB: return "UDUB";
4569 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4570 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004571 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4572 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004573 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4574 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4575 case RIL_REQUEST_DTMF: return "DTMF";
4576 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4577 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004578 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004579 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4580 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4581 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4582 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4583 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4584 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4585 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4586 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4587 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4588 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4589 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4590 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4591 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004592 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004593 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4594 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4595 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4596 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4597 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4598 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4599 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4600 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4601 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4602 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4603 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4604 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4605 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4606 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4607 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4608 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4609 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004610 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4611 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004612 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4613 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4614 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004615 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4616 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004617 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4618 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4619 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4620 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4621 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4622 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4623 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4624 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004625 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004626 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4627 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4628 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4629 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4630 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4631 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4632 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4633 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4634 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4635 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004636 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4637 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4638 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4639 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4640 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004641 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004642 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4643 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4644 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4645 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004646 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4647 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4648 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004649 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004650 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004651 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004652 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004653 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4654 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004655 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004656 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4657 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004658 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004659 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4660 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004661 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4662 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4663 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4664 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Etan Cohend3652192014-06-20 08:28:44 -07004665 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4666 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004667 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4668 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004669 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4670 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004671 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004672 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4673 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004674 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 -08004675 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4676 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4677 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4678 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4679 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4680 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4681 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4682 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4683 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4684 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4685 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4686 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4687 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004688 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004689 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004690 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4691 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4692 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4693 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004694 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4695 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4696 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4697 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4698 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004699 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004700 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004701 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004702 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004703 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4704 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004705 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004706 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004707 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004708 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004709 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4710 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4711 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004712 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004713 default: return "<unknown request>";
4714 }
4715}
4716
Etan Cohend3652192014-06-20 08:28:44 -07004717const char *
4718rilSocketIdToString(RIL_SOCKET_ID socket_id)
4719{
4720 switch(socket_id) {
4721 case RIL_SOCKET_1:
4722 return "RIL_SOCKET_1";
4723#if (SIM_COUNT >= 2)
4724 case RIL_SOCKET_2:
4725 return "RIL_SOCKET_2";
4726#endif
4727#if (SIM_COUNT >= 3)
4728 case RIL_SOCKET_3:
4729 return "RIL_SOCKET_3";
4730#endif
4731#if (SIM_COUNT >= 4)
4732 case RIL_SOCKET_4:
4733 return "RIL_SOCKET_4";
4734#endif
4735 default:
4736 return "not a valid RIL";
4737 }
4738}
4739
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004740} /* namespace android */