blob: 8936f3656143ce322eb7b6b7e7b30224b3d61464 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
22#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070023#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080024#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070026#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070030#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <cutils/jstring.h>
32
33#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070034#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
68
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Constants for response types */
84#define RESPONSE_SOLICITED 0
85#define RESPONSE_UNSOLICITED 1
86
87/* Negative values for private RIL errno's */
88#define RIL_ERRNO_INVALID_RESPONSE -1
89
90// request, response, and unsolicited msg print macro
91#define PRINTBUF_SIZE 8096
92
93// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
108 #define appendPrintBuf(x...) sprintf(printBuf, x)
109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700136 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700141 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142} RequestInfo;
143
Wink Saville3d54e742009-05-18 18:00:44 -0700144typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Etan Cohend3652192014-06-20 08:28:44 -0700151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
185static struct ril_event s_commands_event;
186static struct ril_event s_wakeupfd_event;
187static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700188static SocketListenParam s_ril_param_socket;
189
190static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests = NULL;
193
194#if (SIM_COUNT >= 2)
195static struct ril_event s_commands_event_socket2;
196static struct ril_event s_listen_event_socket2;
197static SocketListenParam s_ril_param_socket2;
198
199static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
200static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
201static RequestInfo *s_pendingRequests_socket2 = NULL;
202#endif
203
204#if (SIM_COUNT >= 3)
205static struct ril_event s_commands_event_socket3;
206static struct ril_event s_listen_event_socket3;
207static SocketListenParam s_ril_param_socket3;
208
209static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
210static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
211static RequestInfo *s_pendingRequests_socket3 = NULL;
212#endif
213
214#if (SIM_COUNT >= 4)
215static struct ril_event s_commands_event_socket4;
216static struct ril_event s_listen_event_socket4;
217static SocketListenParam s_ril_param_socket4;
218
219static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
220static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
221static RequestInfo *s_pendingRequests_socket4 = NULL;
222#endif
223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static struct ril_event s_wake_timeout_event;
225static struct ril_event s_debug_event;
226
227
228static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
229
Etan Cohend3652192014-06-20 08:28:44 -0700230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233
234static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
236
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800237static RequestInfo *s_toDispatchHead = NULL;
238static RequestInfo *s_toDispatchTail = NULL;
239
240static UserCallbackInfo *s_last_wake_timeout_info = NULL;
241
242static void *s_lastNITZTimeData = NULL;
243static size_t s_lastNITZTimeDataSize;
244
245#if RILC_LOG
246 static char printBuf[PRINTBUF_SIZE];
247#endif
248
249/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700250static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800251
252static void dispatchVoid (Parcel& p, RequestInfo *pRI);
253static void dispatchString (Parcel& p, RequestInfo *pRI);
254static void dispatchStrings (Parcel& p, RequestInfo *pRI);
255static void dispatchInts (Parcel& p, RequestInfo *pRI);
256static void dispatchDial (Parcel& p, RequestInfo *pRI);
257static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800258static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
260static void dispatchRaw(Parcel& p, RequestInfo *pRI);
261static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700262static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800263static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700264static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800265static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800266
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700268static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
269static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
270static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700272static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700273static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
274static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800275static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
276static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700277static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700278static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000279static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700280static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800281static int responseInts(Parcel &p, void *response, size_t responselen);
282static int responseStrings(Parcel &p, void *response, size_t responselen);
283static int responseString(Parcel &p, void *response, size_t responselen);
284static int responseVoid(Parcel &p, void *response, size_t responselen);
285static int responseCallList(Parcel &p, void *response, size_t responselen);
286static int responseSMS(Parcel &p, void *response, size_t responselen);
287static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
288static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700289static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800290static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800291static int responseRaw(Parcel &p, void *response, size_t responselen);
292static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700294static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
295static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700296static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800297static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700298static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
299static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
300static int responseCallRing(Parcel &p, void *response, size_t responselen);
301static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
302static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800303static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700304static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700305static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700306static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700307static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800308static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
309static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
310static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
311
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800312#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700313#if defined(ANDROID_MULTI_SIM)
314extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
315 size_t datalen, RIL_SOCKET_ID socket_id);
316#else
Wink Saville7f856802009-06-09 10:23:37 -0700317extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800318 size_t datalen);
319#endif
Etan Cohend3652192014-06-20 08:28:44 -0700320#endif
321
322#if defined(ANDROID_MULTI_SIM)
323#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
324#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
325#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
326#else
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
330#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331
Wink Saville7f856802009-06-09 10:23:37 -0700332static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700333 (RIL_TimedCallback callback, void *param,
334 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
336/** Index == requestNumber */
337static CommandInfo s_commands[] = {
338#include "ril_commands.h"
339};
340
341static UnsolResponseInfo s_unsolResponses[] = {
342#include "ril_unsol_commands.h"
343};
344
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800345/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
346 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
347 radio state message and store it. Every time there is a change in Radio State
348 check to see if voice radio tech changes and notify telephony
349 */
350int voiceRadioTech = -1;
351
352/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
353 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
354 source from radio state and store it. Every time there is a change in Radio State
355 check to see if subscription source changed and notify telephony
356 */
357int cdmaSubscriptionSource = -1;
358
359/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
360 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
361 check to see if SIM/RUIM status changed and notify telephony
362 */
363int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800364
Etan Cohend3652192014-06-20 08:28:44 -0700365static char * RIL_getRilSocketName() {
366 return rild;
367}
368
369extern "C"
370void RIL_setRilSocketName(char * s) {
371 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
372}
373
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800374static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700375strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800376 size_t stringlen;
377 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700378
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700380
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800381 return strndup16to8(s16, stringlen);
382}
383
Wink Saville8b4e4f72014-10-17 15:01:45 -0700384static status_t
385readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
386 size_t s16Len;
387 const char16_t *s16;
388
389 s16 = p.readString16Inplace(&s16Len);
390 if (s16 == NULL) {
391 return NO_MEMORY;
392 }
393 size_t strLen = strnlen16to8(s16, s16Len);
394 if ((strLen + 1) > maxLen) {
395 return NO_MEMORY;
396 }
397 if (strncpy16to8(str, s16, strLen) == NULL) {
398 return NO_MEMORY;
399 } else {
400 return NO_ERROR;
401 }
402}
403
Wink Savillef4c4d362009-04-02 01:37:03 -0700404static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800405 char16_t *s16;
406 size_t s16_len;
407 s16 = strdup8to16(s, &s16_len);
408 p.writeString16(s16, s16_len);
409 free(s16);
410}
411
412
413static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700414memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800415 if (s != NULL) {
416 memset (s, 0, strlen(s));
417 }
418}
419
420void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
421 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700422 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800423 // do nothing -- the data reference lives longer than the Parcel object
424}
425
Wink Saville7f856802009-06-09 10:23:37 -0700426/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 * To be called from dispatch thread
428 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700429 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430 */
431static void
Etan Cohend3652192014-06-20 08:28:44 -0700432issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433 RequestInfo *pRI;
434 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700435 /* Hook for current context */
436 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
437 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
438 /* pendingRequestsHook refer to &s_pendingRequests */
439 RequestInfo** pendingRequestsHook = &s_pendingRequests;
440
441#if (SIM_COUNT == 2)
442 if (socket_id == RIL_SOCKET_2) {
443 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
444 pendingRequestsHook = &s_pendingRequests_socket2;
445 }
446#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800447
448 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
449
450 pRI->local = 1;
451 pRI->token = 0xffffffff; // token is not used in this context
452 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700453 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800454
Etan Cohend3652192014-06-20 08:28:44 -0700455 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800456 assert (ret == 0);
457
Etan Cohend3652192014-06-20 08:28:44 -0700458 pRI->p_next = *pendingRequestsHook;
459 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460
Etan Cohend3652192014-06-20 08:28:44 -0700461 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462 assert (ret == 0);
463
Wink Saville8eb2a122012-11-19 16:05:13 -0800464 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465
Etan Cohend3652192014-06-20 08:28:44 -0700466 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800467}
468
469
470
471static int
Etan Cohend3652192014-06-20 08:28:44 -0700472processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800473 Parcel p;
474 status_t status;
475 int32_t request;
476 int32_t token;
477 RequestInfo *pRI;
478 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700479 /* Hook for current context */
480 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
481 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
482 /* pendingRequestsHook refer to &s_pendingRequests */
483 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800484
485 p.setData((uint8_t *) buffer, buflen);
486
487 // status checked at end
488 status = p.readInt32(&request);
489 status = p.readInt32 (&token);
490
Etan Cohend3652192014-06-20 08:28:44 -0700491 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
492
493#if (SIM_COUNT >= 2)
494 if (socket_id == RIL_SOCKET_2) {
495 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
496 pendingRequestsHook = &s_pendingRequests_socket2;
497 }
498#if (SIM_COUNT >= 3)
499 else if (socket_id == RIL_SOCKET_3) {
500 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
501 pendingRequestsHook = &s_pendingRequests_socket3;
502 }
503#endif
504#if (SIM_COUNT >= 4)
505 else if (socket_id == RIL_SOCKET_4) {
506 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
507 pendingRequestsHook = &s_pendingRequests_socket4;
508 }
509#endif
510#endif
511
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800512 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800513 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800514 return 0;
515 }
516
517 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700518 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800519 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800520 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700521 pErr.writeInt32 (RESPONSE_SOLICITED);
522 pErr.writeInt32 (token);
523 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
524
525 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800526 return 0;
527 }
528
529
530 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
531
532 pRI->token = token;
533 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700534 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800535
Etan Cohend3652192014-06-20 08:28:44 -0700536 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537 assert (ret == 0);
538
Etan Cohend3652192014-06-20 08:28:44 -0700539 pRI->p_next = *pendingRequestsHook;
540 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541
Etan Cohend3652192014-06-20 08:28:44 -0700542 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800543 assert (ret == 0);
544
545/* sLastDispatchedToken = token; */
546
Wink Saville7f856802009-06-09 10:23:37 -0700547 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800548
549 return 0;
550}
551
552static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700553invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800554 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800555 pRI->token, requestToString(pRI->pCI->requestNumber));
556}
557
558/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700559static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700560dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800561 clearPrintBuf;
562 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700563 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800564}
565
566/** Callee expects const char * */
567static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700568dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800569 status_t status;
570 size_t datalen;
571 size_t stringlen;
572 char *string8 = NULL;
573
574 string8 = strdupReadString(p);
575
576 startRequest;
577 appendPrintBuf("%s%s", printBuf, string8);
578 closeRequest;
579 printRequest(pRI->token, pRI->pCI->requestNumber);
580
Etan Cohend3652192014-06-20 08:28:44 -0700581 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
582 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800583
584#ifdef MEMSET_FREED
585 memsetString(string8);
586#endif
587
588 free(string8);
589 return;
590invalid:
591 invalidCommandBlock(pRI);
592 return;
593}
594
595/** Callee expects const char ** */
596static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700597dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800598 int32_t countStrings;
599 status_t status;
600 size_t datalen;
601 char **pStrings;
602
603 status = p.readInt32 (&countStrings);
604
605 if (status != NO_ERROR) {
606 goto invalid;
607 }
608
609 startRequest;
610 if (countStrings == 0) {
611 // just some non-null pointer
612 pStrings = (char **)alloca(sizeof(char *));
613 datalen = 0;
614 } else if (((int)countStrings) == -1) {
615 pStrings = NULL;
616 datalen = 0;
617 } else {
618 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700619
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800620 pStrings = (char **)alloca(datalen);
621
622 for (int i = 0 ; i < countStrings ; i++) {
623 pStrings[i] = strdupReadString(p);
624 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
625 }
626 }
627 removeLastChar;
628 closeRequest;
629 printRequest(pRI->token, pRI->pCI->requestNumber);
630
Etan Cohend3652192014-06-20 08:28:44 -0700631 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800632
633 if (pStrings != NULL) {
634 for (int i = 0 ; i < countStrings ; i++) {
635#ifdef MEMSET_FREED
636 memsetString (pStrings[i]);
637#endif
638 free(pStrings[i]);
639 }
640
641#ifdef MEMSET_FREED
642 memset(pStrings, 0, datalen);
643#endif
644 }
Wink Saville7f856802009-06-09 10:23:37 -0700645
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800646 return;
647invalid:
648 invalidCommandBlock(pRI);
649 return;
650}
651
652/** Callee expects const int * */
653static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700654dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800655 int32_t count;
656 status_t status;
657 size_t datalen;
658 int *pInts;
659
660 status = p.readInt32 (&count);
661
662 if (status != NO_ERROR || count == 0) {
663 goto invalid;
664 }
665
666 datalen = sizeof(int) * count;
667 pInts = (int *)alloca(datalen);
668
669 startRequest;
670 for (int i = 0 ; i < count ; i++) {
671 int32_t t;
672
673 status = p.readInt32(&t);
674 pInts[i] = (int)t;
675 appendPrintBuf("%s%d,", printBuf, t);
676
677 if (status != NO_ERROR) {
678 goto invalid;
679 }
680 }
681 removeLastChar;
682 closeRequest;
683 printRequest(pRI->token, pRI->pCI->requestNumber);
684
Etan Cohend3652192014-06-20 08:28:44 -0700685 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
686 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800687
688#ifdef MEMSET_FREED
689 memset(pInts, 0, datalen);
690#endif
691
692 return;
693invalid:
694 invalidCommandBlock(pRI);
695 return;
696}
697
698
Wink Saville7f856802009-06-09 10:23:37 -0700699/**
700 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800701 * Payload is:
702 * int32_t status
703 * String pdu
704 */
705static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700706dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800707 RIL_SMS_WriteArgs args;
708 int32_t t;
709 status_t status;
710
711 memset (&args, 0, sizeof(args));
712
713 status = p.readInt32(&t);
714 args.status = (int)t;
715
716 args.pdu = strdupReadString(p);
717
718 if (status != NO_ERROR || args.pdu == NULL) {
719 goto invalid;
720 }
721
722 args.smsc = strdupReadString(p);
723
724 startRequest;
725 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
726 (char*)args.pdu, (char*)args.smsc);
727 closeRequest;
728 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700729
Etan Cohend3652192014-06-20 08:28:44 -0700730 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800731
732#ifdef MEMSET_FREED
733 memsetString (args.pdu);
734#endif
735
736 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700737
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800738#ifdef MEMSET_FREED
739 memset(&args, 0, sizeof(args));
740#endif
741
742 return;
743invalid:
744 invalidCommandBlock(pRI);
745 return;
746}
747
Wink Saville7f856802009-06-09 10:23:37 -0700748/**
749 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800750 * Payload is:
751 * String address
752 * int32_t clir
753 */
754static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700755dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800756 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800757 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800758 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800759 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800760 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800761 status_t status;
762
763 memset (&dial, 0, sizeof(dial));
764
765 dial.address = strdupReadString(p);
766
767 status = p.readInt32(&t);
768 dial.clir = (int)t;
769
770 if (status != NO_ERROR || dial.address == NULL) {
771 goto invalid;
772 }
773
Wink Saville3a4840b2010-04-07 13:29:58 -0700774 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800775 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800776 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800777 } else {
778 status = p.readInt32(&uusPresent);
779
780 if (status != NO_ERROR) {
781 goto invalid;
782 }
783
784 if (uusPresent == 0) {
785 dial.uusInfo = NULL;
786 } else {
787 int32_t len;
788
789 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
790
791 status = p.readInt32(&t);
792 uusInfo.uusType = (RIL_UUS_Type) t;
793
794 status = p.readInt32(&t);
795 uusInfo.uusDcs = (RIL_UUS_DCS) t;
796
797 status = p.readInt32(&len);
798 if (status != NO_ERROR) {
799 goto invalid;
800 }
801
802 // The java code writes -1 for null arrays
803 if (((int) len) == -1) {
804 uusInfo.uusData = NULL;
805 len = 0;
806 } else {
807 uusInfo.uusData = (char*) p.readInplace(len);
808 }
809
810 uusInfo.uusLength = len;
811 dial.uusInfo = &uusInfo;
812 }
Wink Saville7bce0822010-01-08 15:20:12 -0800813 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800814 }
815
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800816 startRequest;
817 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800818 if (uusPresent) {
819 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
820 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
821 dial.uusInfo->uusLength);
822 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800823 closeRequest;
824 printRequest(pRI->token, pRI->pCI->requestNumber);
825
Etan Cohend3652192014-06-20 08:28:44 -0700826 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800827
828#ifdef MEMSET_FREED
829 memsetString (dial.address);
830#endif
831
832 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700833
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800834#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800835 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800836 memset(&dial, 0, sizeof(dial));
837#endif
838
839 return;
840invalid:
841 invalidCommandBlock(pRI);
842 return;
843}
844
Wink Saville7f856802009-06-09 10:23:37 -0700845/**
846 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800847 * Payload is:
848 * int32_t command
849 * int32_t fileid
850 * String path
851 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700852 * String data
853 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800854 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800855 */
856static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700857dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800858 union RIL_SIM_IO {
859 RIL_SIM_IO_v6 v6;
860 RIL_SIM_IO_v5 v5;
861 } simIO;
862
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800864 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800865 status_t status;
866
867 memset (&simIO, 0, sizeof(simIO));
868
Wink Saville7f856802009-06-09 10:23:37 -0700869 // note we only check status at the end
870
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800872 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873
874 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800875 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876
Wink Savillec0114b32011-02-18 10:14:07 -0800877 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800878
879 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800880 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800881
882 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800883 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800884
885 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800886 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800887
Wink Savillec0114b32011-02-18 10:14:07 -0800888 simIO.v6.data = strdupReadString(p);
889 simIO.v6.pin2 = strdupReadString(p);
890 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891
892 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800893 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
894 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
895 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
896 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800897 closeRequest;
898 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700899
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800900 if (status != NO_ERROR) {
901 goto invalid;
902 }
903
Wink Savillec0114b32011-02-18 10:14:07 -0800904 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700905 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800906
907#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800908 memsetString (simIO.v6.path);
909 memsetString (simIO.v6.data);
910 memsetString (simIO.v6.pin2);
911 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800912#endif
913
Wink Savillec0114b32011-02-18 10:14:07 -0800914 free (simIO.v6.path);
915 free (simIO.v6.data);
916 free (simIO.v6.pin2);
917 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700918
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800919#ifdef MEMSET_FREED
920 memset(&simIO, 0, sizeof(simIO));
921#endif
922
923 return;
924invalid:
925 invalidCommandBlock(pRI);
926 return;
927}
928
929/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800930 * Callee expects const RIL_SIM_APDU *
931 * Payload is:
932 * int32_t sessionid
933 * int32_t cla
934 * int32_t instruction
935 * int32_t p1, p2, p3
936 * String data
937 */
938static void
939dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
940 int32_t t;
941 status_t status;
942 RIL_SIM_APDU apdu;
943
944 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
945
946 // Note we only check status at the end. Any single failure leads to
947 // subsequent reads filing.
948 status = p.readInt32(&t);
949 apdu.sessionid = (int)t;
950
951 status = p.readInt32(&t);
952 apdu.cla = (int)t;
953
954 status = p.readInt32(&t);
955 apdu.instruction = (int)t;
956
957 status = p.readInt32(&t);
958 apdu.p1 = (int)t;
959
960 status = p.readInt32(&t);
961 apdu.p2 = (int)t;
962
963 status = p.readInt32(&t);
964 apdu.p3 = (int)t;
965
966 apdu.data = strdupReadString(p);
967
968 startRequest;
969 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
970 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
971 apdu.p3, (char*)apdu.data);
972 closeRequest;
973 printRequest(pRI->token, pRI->pCI->requestNumber);
974
975 if (status != NO_ERROR) {
976 goto invalid;
977 }
978
Etan Cohend3652192014-06-20 08:28:44 -0700979 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800980
981#ifdef MEMSET_FREED
982 memsetString(apdu.data);
983#endif
984 free(apdu.data);
985
986#ifdef MEMSET_FREED
987 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
988#endif
989
990 return;
991invalid:
992 invalidCommandBlock(pRI);
993 return;
994}
995
996
997/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800998 * Callee expects const RIL_CallForwardInfo *
999 * Payload is:
1000 * int32_t status/action
1001 * int32_t reason
1002 * int32_t serviceCode
1003 * int32_t toa
1004 * String number (0 length -> null)
1005 * int32_t timeSeconds
1006 */
Wink Saville7f856802009-06-09 10:23:37 -07001007static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001008dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001009 RIL_CallForwardInfo cff;
1010 int32_t t;
1011 status_t status;
1012
1013 memset (&cff, 0, sizeof(cff));
1014
Wink Saville7f856802009-06-09 10:23:37 -07001015 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001016
1017 status = p.readInt32(&t);
1018 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001019
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001020 status = p.readInt32(&t);
1021 cff.reason = (int)t;
1022
1023 status = p.readInt32(&t);
1024 cff.serviceClass = (int)t;
1025
1026 status = p.readInt32(&t);
1027 cff.toa = (int)t;
1028
1029 cff.number = strdupReadString(p);
1030
1031 status = p.readInt32(&t);
1032 cff.timeSeconds = (int)t;
1033
1034 if (status != NO_ERROR) {
1035 goto invalid;
1036 }
1037
1038 // special case: number 0-length fields is null
1039
1040 if (cff.number != NULL && strlen (cff.number) == 0) {
1041 cff.number = NULL;
1042 }
1043
1044 startRequest;
1045 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1046 cff.status, cff.reason, cff.serviceClass, cff.toa,
1047 (char*)cff.number, cff.timeSeconds);
1048 closeRequest;
1049 printRequest(pRI->token, pRI->pCI->requestNumber);
1050
Etan Cohend3652192014-06-20 08:28:44 -07001051 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001052
1053#ifdef MEMSET_FREED
1054 memsetString(cff.number);
1055#endif
1056
1057 free (cff.number);
1058
1059#ifdef MEMSET_FREED
1060 memset(&cff, 0, sizeof(cff));
1061#endif
1062
1063 return;
1064invalid:
1065 invalidCommandBlock(pRI);
1066 return;
1067}
1068
1069
Wink Saville7f856802009-06-09 10:23:37 -07001070static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001071dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001072 int32_t len;
1073 status_t status;
1074 const void *data;
1075
1076 status = p.readInt32(&len);
1077
1078 if (status != NO_ERROR) {
1079 goto invalid;
1080 }
1081
1082 // The java code writes -1 for null arrays
1083 if (((int)len) == -1) {
1084 data = NULL;
1085 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001086 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001087
1088 data = p.readInplace(len);
1089
1090 startRequest;
1091 appendPrintBuf("%sraw_size=%d", printBuf, len);
1092 closeRequest;
1093 printRequest(pRI->token, pRI->pCI->requestNumber);
1094
Etan Cohend3652192014-06-20 08:28:44 -07001095 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001096
1097 return;
1098invalid:
1099 invalidCommandBlock(pRI);
1100 return;
1101}
1102
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001103static status_t
1104constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001105 int32_t t;
1106 uint8_t ut;
1107 status_t status;
1108 int32_t digitCount;
1109 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001110
Wink Savillef4c4d362009-04-02 01:37:03 -07001111 memset(&rcsm, 0, sizeof(rcsm));
1112
1113 status = p.readInt32(&t);
1114 rcsm.uTeleserviceID = (int) t;
1115
1116 status = p.read(&ut,sizeof(ut));
1117 rcsm.bIsServicePresent = (uint8_t) ut;
1118
1119 status = p.readInt32(&t);
1120 rcsm.uServicecategory = (int) t;
1121
1122 status = p.readInt32(&t);
1123 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1124
1125 status = p.readInt32(&t);
1126 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1127
1128 status = p.readInt32(&t);
1129 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1130
1131 status = p.readInt32(&t);
1132 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1133
1134 status = p.read(&ut,sizeof(ut));
1135 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1136
1137 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1138 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1139 status = p.read(&ut,sizeof(ut));
1140 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1141 }
1142
Wink Saville7f856802009-06-09 10:23:37 -07001143 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001144 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1145
Wink Saville7f856802009-06-09 10:23:37 -07001146 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001147 rcsm.sSubAddress.odd = (uint8_t) ut;
1148
1149 status = p.read(&ut,sizeof(ut));
1150 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1151
1152 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001153 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1154 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001155 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1156 }
1157
Wink Saville7f856802009-06-09 10:23:37 -07001158 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 rcsm.uBearerDataLen = (int) t;
1160
1161 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001162 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1163 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001164 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1165 }
1166
1167 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001168 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001169 }
1170
1171 startRequest;
1172 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001173 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001174 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001175 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001176 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001177
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 printRequest(pRI->token, pRI->pCI->requestNumber);
1179
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001180 return status;
1181}
1182
1183static void
1184dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1185 RIL_CDMA_SMS_Message rcsm;
1186
1187 ALOGD("dispatchCdmaSms");
1188 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1189 goto invalid;
1190 }
1191
Etan Cohend3652192014-06-20 08:28:44 -07001192 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001193
1194#ifdef MEMSET_FREED
1195 memset(&rcsm, 0, sizeof(rcsm));
1196#endif
1197
1198 return;
1199
1200invalid:
1201 invalidCommandBlock(pRI);
1202 return;
1203}
1204
Wink Saville7f856802009-06-09 10:23:37 -07001205static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001206dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1207 RIL_IMS_SMS_Message rism;
1208 RIL_CDMA_SMS_Message rcsm;
1209
1210 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1211
1212 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1213 goto invalid;
1214 }
1215 memset(&rism, 0, sizeof(rism));
1216 rism.tech = RADIO_TECH_3GPP2;
1217 rism.retry = retry;
1218 rism.messageRef = messageRef;
1219 rism.message.cdmaMessage = &rcsm;
1220
Etan Cohend3652192014-06-20 08:28:44 -07001221 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001222 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001223 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001224
1225#ifdef MEMSET_FREED
1226 memset(&rcsm, 0, sizeof(rcsm));
1227 memset(&rism, 0, sizeof(rism));
1228#endif
1229
1230 return;
1231
1232invalid:
1233 invalidCommandBlock(pRI);
1234 return;
1235}
1236
1237static void
1238dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1239 RIL_IMS_SMS_Message rism;
1240 int32_t countStrings;
1241 status_t status;
1242 size_t datalen;
1243 char **pStrings;
1244 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1245
1246 status = p.readInt32 (&countStrings);
1247
1248 if (status != NO_ERROR) {
1249 goto invalid;
1250 }
1251
1252 memset(&rism, 0, sizeof(rism));
1253 rism.tech = RADIO_TECH_3GPP;
1254 rism.retry = retry;
1255 rism.messageRef = messageRef;
1256
1257 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001258 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1259 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001260 if (countStrings == 0) {
1261 // just some non-null pointer
1262 pStrings = (char **)alloca(sizeof(char *));
1263 datalen = 0;
1264 } else if (((int)countStrings) == -1) {
1265 pStrings = NULL;
1266 datalen = 0;
1267 } else {
1268 datalen = sizeof(char *) * countStrings;
1269
1270 pStrings = (char **)alloca(datalen);
1271
1272 for (int i = 0 ; i < countStrings ; i++) {
1273 pStrings[i] = strdupReadString(p);
1274 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1275 }
1276 }
1277 removeLastChar;
1278 closeRequest;
1279 printRequest(pRI->token, pRI->pCI->requestNumber);
1280
1281 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001282 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001283 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001284 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001285
1286 if (pStrings != NULL) {
1287 for (int i = 0 ; i < countStrings ; i++) {
1288#ifdef MEMSET_FREED
1289 memsetString (pStrings[i]);
1290#endif
1291 free(pStrings[i]);
1292 }
1293
1294#ifdef MEMSET_FREED
1295 memset(pStrings, 0, datalen);
1296#endif
1297 }
1298
1299#ifdef MEMSET_FREED
1300 memset(&rism, 0, sizeof(rism));
1301#endif
1302 return;
1303invalid:
1304 ALOGE("dispatchImsGsmSms invalid block");
1305 invalidCommandBlock(pRI);
1306 return;
1307}
1308
1309static void
1310dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1311 int32_t t;
1312 status_t status = p.readInt32(&t);
1313 RIL_RadioTechnologyFamily format;
1314 uint8_t retry;
1315 int32_t messageRef;
1316
1317 ALOGD("dispatchImsSms");
1318 if (status != NO_ERROR) {
1319 goto invalid;
1320 }
1321 format = (RIL_RadioTechnologyFamily) t;
1322
1323 // read retry field
1324 status = p.read(&retry,sizeof(retry));
1325 if (status != NO_ERROR) {
1326 goto invalid;
1327 }
1328 // read messageRef field
1329 status = p.read(&messageRef,sizeof(messageRef));
1330 if (status != NO_ERROR) {
1331 goto invalid;
1332 }
1333
1334 if (RADIO_TECH_3GPP == format) {
1335 dispatchImsGsmSms(p, pRI, retry, messageRef);
1336 } else if (RADIO_TECH_3GPP2 == format) {
1337 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1338 } else {
1339 ALOGE("requestImsSendSMS invalid format value =%d", format);
1340 }
1341
1342 return;
1343
1344invalid:
1345 invalidCommandBlock(pRI);
1346 return;
1347}
1348
1349static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001350dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1351 RIL_CDMA_SMS_Ack rcsa;
1352 int32_t t;
1353 status_t status;
1354 int32_t digitCount;
1355
1356 memset(&rcsa, 0, sizeof(rcsa));
1357
1358 status = p.readInt32(&t);
1359 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1360
1361 status = p.readInt32(&t);
1362 rcsa.uSMSCauseCode = (int) t;
1363
1364 if (status != NO_ERROR) {
1365 goto invalid;
1366 }
1367
1368 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001369 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1370 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001371 closeRequest;
1372
1373 printRequest(pRI->token, pRI->pCI->requestNumber);
1374
Etan Cohend3652192014-06-20 08:28:44 -07001375 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001376
1377#ifdef MEMSET_FREED
1378 memset(&rcsa, 0, sizeof(rcsa));
1379#endif
1380
1381 return;
1382
1383invalid:
1384 invalidCommandBlock(pRI);
1385 return;
1386}
1387
Wink Savillea592eeb2009-05-22 13:26:36 -07001388static void
1389dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1390 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001391 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001392 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001393
Wink Savillea592eeb2009-05-22 13:26:36 -07001394 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001395 if (status != NO_ERROR) {
1396 goto invalid;
1397 }
1398
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001399 {
1400 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1401 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001402
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001403 startRequest;
1404 for (int i = 0 ; i < num ; i++ ) {
1405 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001406
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001407 status = p.readInt32(&t);
1408 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001409
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001410 status = p.readInt32(&t);
1411 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001412
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001413 status = p.readInt32(&t);
1414 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001415
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001416 status = p.readInt32(&t);
1417 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001418
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 status = p.readInt32(&t);
1420 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001422 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1423 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1424 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1425 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1426 gsmBci[i].selected);
1427 }
1428 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001429
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001430 if (status != NO_ERROR) {
1431 goto invalid;
1432 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001433
Etan Cohend3652192014-06-20 08:28:44 -07001434 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001435 gsmBciPtrs,
1436 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001437 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001438
1439#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001440 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1441 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001442#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001443 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001444
1445 return;
1446
1447invalid:
1448 invalidCommandBlock(pRI);
1449 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001450}
Wink Savillef4c4d362009-04-02 01:37:03 -07001451
Wink Savillea592eeb2009-05-22 13:26:36 -07001452static void
1453dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1454 int32_t t;
1455 status_t status;
1456 int32_t num;
1457
1458 status = p.readInt32(&num);
1459 if (status != NO_ERROR) {
1460 goto invalid;
1461 }
1462
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001463 {
1464 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1465 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001466
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 startRequest;
1468 for (int i = 0 ; i < num ; i++ ) {
1469 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001470
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001471 status = p.readInt32(&t);
1472 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001473
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001474 status = p.readInt32(&t);
1475 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001476
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001477 status = p.readInt32(&t);
1478 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001480 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1481 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1482 cdmaBci[i].language, cdmaBci[i].selected);
1483 }
1484 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001486 if (status != NO_ERROR) {
1487 goto invalid;
1488 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001489
Etan Cohend3652192014-06-20 08:28:44 -07001490 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001491 cdmaBciPtrs,
1492 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001493 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001494
1495#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001496 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1497 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001498#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001499 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001500
1501 return;
1502
1503invalid:
1504 invalidCommandBlock(pRI);
1505 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001506}
1507
1508static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1509 RIL_CDMA_SMS_WriteArgs rcsw;
1510 int32_t t;
1511 uint32_t ut;
1512 uint8_t uct;
1513 status_t status;
1514 int32_t digitCount;
1515
1516 memset(&rcsw, 0, sizeof(rcsw));
1517
1518 status = p.readInt32(&t);
1519 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001520
Wink Savillef4c4d362009-04-02 01:37:03 -07001521 status = p.readInt32(&t);
1522 rcsw.message.uTeleserviceID = (int) t;
1523
1524 status = p.read(&uct,sizeof(uct));
1525 rcsw.message.bIsServicePresent = (uint8_t) uct;
1526
1527 status = p.readInt32(&t);
1528 rcsw.message.uServicecategory = (int) t;
1529
1530 status = p.readInt32(&t);
1531 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1532
1533 status = p.readInt32(&t);
1534 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1535
1536 status = p.readInt32(&t);
1537 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1538
1539 status = p.readInt32(&t);
1540 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1541
1542 status = p.read(&uct,sizeof(uct));
1543 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1544
1545 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1546 status = p.read(&uct,sizeof(uct));
1547 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1548 }
1549
Wink Savillea592eeb2009-05-22 13:26:36 -07001550 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001551 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1552
Wink Savillea592eeb2009-05-22 13:26:36 -07001553 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001554 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1555
1556 status = p.read(&uct,sizeof(uct));
1557 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1558
1559 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001560 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001561 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1562 }
1563
Wink Savillea592eeb2009-05-22 13:26:36 -07001564 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001565 rcsw.message.uBearerDataLen = (int) t;
1566
1567 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001568 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001569 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1570 }
1571
1572 if (status != NO_ERROR) {
1573 goto invalid;
1574 }
1575
1576 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001577 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1578 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1579 message.sAddress.number_mode=%d, \
1580 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001581 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001582 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1583 rcsw.message.sAddress.number_mode,
1584 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 closeRequest;
1586
1587 printRequest(pRI->token, pRI->pCI->requestNumber);
1588
Etan Cohend3652192014-06-20 08:28:44 -07001589 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001590
1591#ifdef MEMSET_FREED
1592 memset(&rcsw, 0, sizeof(rcsw));
1593#endif
1594
1595 return;
1596
1597invalid:
1598 invalidCommandBlock(pRI);
1599 return;
1600
1601}
1602
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001603// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1604// Version 4 of the RIL interface adds a new PDP type parameter to support
1605// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1606// RIL, remove the parameter from the request.
1607static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1608 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1609 const int numParamsRilV3 = 6;
1610
1611 // The first bytes of the RIL parcel contain the request number and the
1612 // serial number - see processCommandBuffer(). Copy them over too.
1613 int pos = p.dataPosition();
1614
1615 int numParams = p.readInt32();
1616 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1617 Parcel p2;
1618 p2.appendFrom(&p, 0, pos);
1619 p2.writeInt32(numParamsRilV3);
1620 for(int i = 0; i < numParamsRilV3; i++) {
1621 p2.writeString16(p.readString16());
1622 }
1623 p2.setDataPosition(pos);
1624 dispatchStrings(p2, pRI);
1625 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001626 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001627 dispatchStrings(p, pRI);
1628 }
1629}
1630
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001631// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1632// When all RILs handle this request, this function can be removed and
1633// the request can be sent directly to the RIL using dispatchVoid.
1634static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001635 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001636
1637 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1638 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1639 }
1640
1641 // RILs that support RADIO_STATE_ON should support this request.
1642 if (RADIO_STATE_ON == state) {
1643 dispatchVoid(p, pRI);
1644 return;
1645 }
1646
1647 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1648 // will not support this new request either and decode Voice Radio Technology
1649 // from Radio State
1650 voiceRadioTech = decodeVoiceRadioTechnology(state);
1651
1652 if (voiceRadioTech < 0)
1653 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1654 else
1655 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1656}
1657
1658// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1659// When all RILs handle this request, this function can be removed and
1660// the request can be sent directly to the RIL using dispatchVoid.
1661static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001662 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001663
1664 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1665 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1666 }
1667
1668 // RILs that support RADIO_STATE_ON should support this request.
1669 if (RADIO_STATE_ON == state) {
1670 dispatchVoid(p, pRI);
1671 return;
1672 }
1673
1674 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1675 // will not support this new request either and decode CDMA Subscription Source
1676 // from Radio State
1677 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1678
1679 if (cdmaSubscriptionSource < 0)
1680 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1681 else
1682 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1683}
1684
Sungmin Choi75697532013-04-26 15:04:45 -07001685static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1686{
1687 RIL_InitialAttachApn pf;
1688 int32_t t;
1689 status_t status;
1690
1691 memset(&pf, 0, sizeof(pf));
1692
1693 pf.apn = strdupReadString(p);
1694 pf.protocol = strdupReadString(p);
1695
1696 status = p.readInt32(&t);
1697 pf.authtype = (int) t;
1698
1699 pf.username = strdupReadString(p);
1700 pf.password = strdupReadString(p);
1701
1702 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001703 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1704 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001705 closeRequest;
1706 printRequest(pRI->token, pRI->pCI->requestNumber);
1707
1708 if (status != NO_ERROR) {
1709 goto invalid;
1710 }
Etan Cohend3652192014-06-20 08:28:44 -07001711 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001712
1713#ifdef MEMSET_FREED
1714 memsetString(pf.apn);
1715 memsetString(pf.protocol);
1716 memsetString(pf.username);
1717 memsetString(pf.password);
1718#endif
1719
1720 free(pf.apn);
1721 free(pf.protocol);
1722 free(pf.username);
1723 free(pf.password);
1724
1725#ifdef MEMSET_FREED
1726 memset(&pf, 0, sizeof(pf));
1727#endif
1728
1729 return;
1730invalid:
1731 invalidCommandBlock(pRI);
1732 return;
1733}
1734
Jake Hamby8a4a2332014-01-15 13:12:05 -08001735static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1736 RIL_NV_ReadItem nvri;
1737 int32_t t;
1738 status_t status;
1739
1740 memset(&nvri, 0, sizeof(nvri));
1741
1742 status = p.readInt32(&t);
1743 nvri.itemID = (RIL_NV_Item) t;
1744
1745 if (status != NO_ERROR) {
1746 goto invalid;
1747 }
1748
1749 startRequest;
1750 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1751 closeRequest;
1752
1753 printRequest(pRI->token, pRI->pCI->requestNumber);
1754
Etan Cohend3652192014-06-20 08:28:44 -07001755 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001756
1757#ifdef MEMSET_FREED
1758 memset(&nvri, 0, sizeof(nvri));
1759#endif
1760
1761 return;
1762
1763invalid:
1764 invalidCommandBlock(pRI);
1765 return;
1766}
1767
1768static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1769 RIL_NV_WriteItem nvwi;
1770 int32_t t;
1771 status_t status;
1772
1773 memset(&nvwi, 0, sizeof(nvwi));
1774
1775 status = p.readInt32(&t);
1776 nvwi.itemID = (RIL_NV_Item) t;
1777
1778 nvwi.value = strdupReadString(p);
1779
1780 if (status != NO_ERROR || nvwi.value == NULL) {
1781 goto invalid;
1782 }
1783
1784 startRequest;
1785 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1786 nvwi.value);
1787 closeRequest;
1788
1789 printRequest(pRI->token, pRI->pCI->requestNumber);
1790
Etan Cohend3652192014-06-20 08:28:44 -07001791 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001792
1793#ifdef MEMSET_FREED
1794 memsetString(nvwi.value);
1795#endif
1796
1797 free(nvwi.value);
1798
1799#ifdef MEMSET_FREED
1800 memset(&nvwi, 0, sizeof(nvwi));
1801#endif
1802
1803 return;
1804
1805invalid:
1806 invalidCommandBlock(pRI);
1807 return;
1808}
1809
1810
Etan Cohend3652192014-06-20 08:28:44 -07001811static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1812 RIL_SelectUiccSub uicc_sub;
1813 status_t status;
1814 int32_t t;
1815 memset(&uicc_sub, 0, sizeof(uicc_sub));
1816
1817 status = p.readInt32(&t);
1818 if (status != NO_ERROR) {
1819 goto invalid;
1820 }
1821 uicc_sub.slot = (int) t;
1822
1823 status = p.readInt32(&t);
1824 if (status != NO_ERROR) {
1825 goto invalid;
1826 }
1827 uicc_sub.app_index = (int) t;
1828
1829 status = p.readInt32(&t);
1830 if (status != NO_ERROR) {
1831 goto invalid;
1832 }
1833 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1834
1835 status = p.readInt32(&t);
1836 if (status != NO_ERROR) {
1837 goto invalid;
1838 }
1839 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1840
1841 startRequest;
1842 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1843 uicc_sub.act_status);
1844 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1845 uicc_sub.app_index, uicc_sub.act_status);
1846 closeRequest;
1847 printRequest(pRI->token, pRI->pCI->requestNumber);
1848
1849 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1850
1851#ifdef MEMSET_FREED
1852 memset(&uicc_sub, 0, sizeof(uicc_sub));
1853#endif
1854 return;
1855
1856invalid:
1857 invalidCommandBlock(pRI);
1858 return;
1859}
1860
Amit Mahajan90530a62014-07-01 15:54:08 -07001861static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1862{
1863 RIL_SimAuthentication pf;
1864 int32_t t;
1865 status_t status;
1866
1867 memset(&pf, 0, sizeof(pf));
1868
1869 status = p.readInt32(&t);
1870 pf.authContext = (int) t;
1871 pf.authData = strdupReadString(p);
1872 pf.aid = strdupReadString(p);
1873
1874 startRequest;
1875 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1876 closeRequest;
1877 printRequest(pRI->token, pRI->pCI->requestNumber);
1878
1879 if (status != NO_ERROR) {
1880 goto invalid;
1881 }
1882 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1883
1884#ifdef MEMSET_FREED
1885 memsetString(pf.authData);
1886 memsetString(pf.aid);
1887#endif
1888
1889 free(pf.authData);
1890 free(pf.aid);
1891
1892#ifdef MEMSET_FREED
1893 memset(&pf, 0, sizeof(pf));
1894#endif
1895
1896 return;
1897invalid:
1898 invalidCommandBlock(pRI);
1899 return;
1900}
1901
Amit Mahajanc796e222014-08-13 16:54:01 +00001902static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1903 int32_t t;
1904 status_t status;
1905 int32_t num;
1906
1907 status = p.readInt32(&num);
1908 if (status != NO_ERROR) {
1909 goto invalid;
1910 }
1911
1912 {
1913 RIL_DataProfileInfo dataProfiles[num];
1914 RIL_DataProfileInfo *dataProfilePtrs[num];
1915
1916 startRequest;
1917 for (int i = 0 ; i < num ; i++ ) {
1918 dataProfilePtrs[i] = &dataProfiles[i];
1919
1920 status = p.readInt32(&t);
1921 dataProfiles[i].profileId = (int) t;
1922
1923 dataProfiles[i].apn = strdupReadString(p);
1924 dataProfiles[i].protocol = strdupReadString(p);
1925 status = p.readInt32(&t);
1926 dataProfiles[i].authType = (int) t;
1927
1928 dataProfiles[i].user = strdupReadString(p);
1929 dataProfiles[i].password = strdupReadString(p);
1930
1931 status = p.readInt32(&t);
1932 dataProfiles[i].type = (int) t;
1933
1934 status = p.readInt32(&t);
1935 dataProfiles[i].maxConnsTime = (int) t;
1936 status = p.readInt32(&t);
1937 dataProfiles[i].maxConns = (int) t;
1938 status = p.readInt32(&t);
1939 dataProfiles[i].waitTime = (int) t;
1940
1941 status = p.readInt32(&t);
1942 dataProfiles[i].enabled = (int) t;
1943
1944 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1945 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1946 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1947 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1948 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1949 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1950 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1951 }
1952 closeRequest;
1953 printRequest(pRI->token, pRI->pCI->requestNumber);
1954
1955 if (status != NO_ERROR) {
1956 goto invalid;
1957 }
1958 CALL_ONREQUEST(pRI->pCI->requestNumber,
1959 dataProfilePtrs,
1960 num * sizeof(RIL_DataProfileInfo *),
1961 pRI, pRI->socket_id);
1962
1963#ifdef MEMSET_FREED
1964 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1965 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1966#endif
1967 }
1968
1969 return;
1970
1971invalid:
1972 invalidCommandBlock(pRI);
1973 return;
1974}
1975
Wink Saville8b4e4f72014-10-17 15:01:45 -07001976static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1977 RIL_RadioCapability rc;
1978 int32_t t;
1979 status_t status;
1980
1981 memset (&rc, 0, sizeof(RIL_RadioCapability));
1982
1983 status = p.readInt32(&t);
1984 rc.version = (int)t;
1985 if (status != NO_ERROR) {
1986 goto invalid;
1987 }
1988
1989 status = p.readInt32(&t);
1990 rc.session= (int)t;
1991 if (status != NO_ERROR) {
1992 goto invalid;
1993 }
1994
1995 status = p.readInt32(&t);
1996 rc.phase= (int)t;
1997 if (status != NO_ERROR) {
1998 goto invalid;
1999 }
2000
2001 status = p.readInt32(&t);
2002 rc.rat = (int)t;
2003 if (status != NO_ERROR) {
2004 goto invalid;
2005 }
2006
2007 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2008 if (status != NO_ERROR) {
2009 goto invalid;
2010 }
2011
2012 status = p.readInt32(&t);
2013 rc.status = (int)t;
2014
2015 if (status != NO_ERROR) {
2016 goto invalid;
2017 }
2018
2019 startRequest;
2020 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002021 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2022 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002023
2024 closeRequest;
2025 printRequest(pRI->token, pRI->pCI->requestNumber);
2026
2027 CALL_ONREQUEST(pRI->pCI->requestNumber,
2028 &rc,
2029 sizeof(RIL_RadioCapability),
2030 pRI, pRI->socket_id);
2031 return;
2032invalid:
2033 invalidCommandBlock(pRI);
2034 return;
2035}
2036
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002037static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002038blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002039 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002040 const uint8_t *toWrite;
2041
2042 toWrite = (const uint8_t *)buffer;
2043
2044 while (writeOffset < len) {
2045 ssize_t written;
2046 do {
2047 written = write (fd, toWrite + writeOffset,
2048 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302049 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002050
2051 if (written >= 0) {
2052 writeOffset += written;
2053 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002054 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002055 close(fd);
2056 return -1;
2057 }
2058 }
2059
2060 return 0;
2061}
2062
2063static int
Etan Cohend3652192014-06-20 08:28:44 -07002064sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2065 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002066 int ret;
2067 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002068 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002069
Etan Cohend3652192014-06-20 08:28:44 -07002070 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2071
2072#if (SIM_COUNT >= 2)
2073 if (socket_id == RIL_SOCKET_2) {
2074 fd = s_ril_param_socket2.fdCommand;
2075 writeMutexHook = &s_writeMutex_socket2;
2076 }
2077#if (SIM_COUNT >= 3)
2078 else if (socket_id == RIL_SOCKET_3) {
2079 fd = s_ril_param_socket3.fdCommand;
2080 writeMutexHook = &s_writeMutex_socket3;
2081 }
2082#endif
2083#if (SIM_COUNT >= 4)
2084 else if (socket_id == RIL_SOCKET_4) {
2085 fd = s_ril_param_socket4.fdCommand;
2086 writeMutexHook = &s_writeMutex_socket4;
2087 }
2088#endif
2089#endif
2090 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002091 return -1;
2092 }
2093
2094 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002095 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002096 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2097
2098 return -1;
2099 }
Wink Saville7f856802009-06-09 10:23:37 -07002100
Etan Cohend3652192014-06-20 08:28:44 -07002101 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002102
2103 header = htonl(dataSize);
2104
2105 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2106
2107 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002108 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002109 return ret;
2110 }
2111
Kennyee1fadc2009-08-13 00:45:53 +08002112 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002113
2114 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002115 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002116 return ret;
2117 }
2118
Etan Cohend3652192014-06-20 08:28:44 -07002119 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002120
2121 return 0;
2122}
2123
2124static int
Etan Cohend3652192014-06-20 08:28:44 -07002125sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002127 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002128}
2129
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002130/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002131
2132static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002133responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002134 int numInts;
2135
2136 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002137 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002138 return RIL_ERRNO_INVALID_RESPONSE;
2139 }
2140 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002141 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002142 (int)responselen, (int)sizeof(int));
2143 return RIL_ERRNO_INVALID_RESPONSE;
2144 }
2145
2146 int *p_int = (int *) response;
2147
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002148 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002149 p.writeInt32 (numInts);
2150
2151 /* each int*/
2152 startResponse;
2153 for (int i = 0 ; i < numInts ; i++) {
2154 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2155 p.writeInt32(p_int[i]);
2156 }
2157 removeLastChar;
2158 closeResponse;
2159
2160 return 0;
2161}
2162
Wink Saville43808972011-01-13 17:39:51 -08002163/** response is a char **, pointing to an array of char *'s
2164 The parcel will begin with the version */
2165static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2166 p.writeInt32(version);
2167 return responseStrings(p, response, responselen);
2168}
2169
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002170/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002171static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002172 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002173
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002174 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002175 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002176 return RIL_ERRNO_INVALID_RESPONSE;
2177 }
2178 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002179 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002180 (int)responselen, (int)sizeof(char *));
2181 return RIL_ERRNO_INVALID_RESPONSE;
2182 }
2183
2184 if (response == NULL) {
2185 p.writeInt32 (0);
2186 } else {
2187 char **p_cur = (char **) response;
2188
2189 numStrings = responselen / sizeof(char *);
2190 p.writeInt32 (numStrings);
2191
2192 /* each string*/
2193 startResponse;
2194 for (int i = 0 ; i < numStrings ; i++) {
2195 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2196 writeStringToParcel (p, p_cur[i]);
2197 }
2198 removeLastChar;
2199 closeResponse;
2200 }
2201 return 0;
2202}
2203
2204
2205/**
Wink Saville7f856802009-06-09 10:23:37 -07002206 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002207 * FIXME currently ignores responselen
2208 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002209static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002210 /* one string only */
2211 startResponse;
2212 appendPrintBuf("%s%s", printBuf, (char*)response);
2213 closeResponse;
2214
2215 writeStringToParcel(p, (const char *)response);
2216
2217 return 0;
2218}
2219
Wink Savillef4c4d362009-04-02 01:37:03 -07002220static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002221 startResponse;
2222 removeLastChar;
2223 return 0;
2224}
2225
Wink Savillef4c4d362009-04-02 01:37:03 -07002226static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002227 int num;
2228
2229 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002230 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002231 return RIL_ERRNO_INVALID_RESPONSE;
2232 }
2233
2234 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002235 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002236 (int)responselen, (int)sizeof (RIL_Call *));
2237 return RIL_ERRNO_INVALID_RESPONSE;
2238 }
2239
2240 startResponse;
2241 /* number of call info's */
2242 num = responselen / sizeof(RIL_Call *);
2243 p.writeInt32(num);
2244
2245 for (int i = 0 ; i < num ; i++) {
2246 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2247 /* each call info */
2248 p.writeInt32(p_cur->state);
2249 p.writeInt32(p_cur->index);
2250 p.writeInt32(p_cur->toa);
2251 p.writeInt32(p_cur->isMpty);
2252 p.writeInt32(p_cur->isMT);
2253 p.writeInt32(p_cur->als);
2254 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002255 p.writeInt32(p_cur->isVoicePrivacy);
2256 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002257 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002258 writeStringToParcel(p, p_cur->name);
2259 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002260 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002261 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2262 p.writeInt32(0); /* UUS Information is absent */
2263 } else {
2264 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2265 p.writeInt32(1); /* UUS Information is present */
2266 p.writeInt32(uusInfo->uusType);
2267 p.writeInt32(uusInfo->uusDcs);
2268 p.writeInt32(uusInfo->uusLength);
2269 p.write(uusInfo->uusData, uusInfo->uusLength);
2270 }
Wink Saville3d54e742009-05-18 18:00:44 -07002271 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002272 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002273 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002274 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002275 p_cur->toa);
2276 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2277 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002278 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002279 (p_cur->isMT)?"mt":"mo",
2280 p_cur->als,
2281 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002282 (p_cur->isVoicePrivacy)?"evp":"noevp");
2283 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2284 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002285 p_cur->number,
2286 p_cur->numberPresentation,
2287 p_cur->name,
2288 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002289 }
2290 removeLastChar;
2291 closeResponse;
2292
2293 return 0;
2294}
2295
Wink Savillef4c4d362009-04-02 01:37:03 -07002296static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002297 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002298 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002299 return RIL_ERRNO_INVALID_RESPONSE;
2300 }
2301
2302 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002303 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002304 (int)responselen, (int)sizeof (RIL_SMS_Response));
2305 return RIL_ERRNO_INVALID_RESPONSE;
2306 }
2307
2308 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2309
2310 p.writeInt32(p_cur->messageRef);
2311 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002312 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002313
2314 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002315 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2316 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002317 closeResponse;
2318
2319 return 0;
2320}
2321
Wink Savillec0114b32011-02-18 10:14:07 -08002322static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002323{
2324 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002325 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002326 return RIL_ERRNO_INVALID_RESPONSE;
2327 }
2328
Wink Savillec0114b32011-02-18 10:14:07 -08002329 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002330 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002331 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002332 return RIL_ERRNO_INVALID_RESPONSE;
2333 }
2334
Amit Mahajan52500162014-07-29 17:36:48 -07002335 // Write version
2336 p.writeInt32(4);
2337
Wink Savillec0114b32011-02-18 10:14:07 -08002338 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002339 p.writeInt32(num);
2340
Wink Savillec0114b32011-02-18 10:14:07 -08002341 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002342 startResponse;
2343 int i;
2344 for (i = 0; i < num; i++) {
2345 p.writeInt32(p_cur[i].cid);
2346 p.writeInt32(p_cur[i].active);
2347 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002348 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002349 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002350 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002351 p_cur[i].cid,
2352 (p_cur[i].active==0)?"down":"up",
2353 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002354 (char*)p_cur[i].address);
2355 }
2356 removeLastChar;
2357 closeResponse;
2358
2359 return 0;
2360}
2361
Etan Cohend3652192014-06-20 08:28:44 -07002362static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2363{
Amit Mahajan52500162014-07-29 17:36:48 -07002364 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002365 RLOGE("invalid response: NULL");
2366 return RIL_ERRNO_INVALID_RESPONSE;
2367 }
2368
2369 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002370 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002371 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2372 return RIL_ERRNO_INVALID_RESPONSE;
2373 }
2374
Amit Mahajan52500162014-07-29 17:36:48 -07002375 // Write version
2376 p.writeInt32(6);
2377
Etan Cohend3652192014-06-20 08:28:44 -07002378 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2379 p.writeInt32(num);
2380
2381 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2382 startResponse;
2383 int i;
2384 for (i = 0; i < num; i++) {
2385 p.writeInt32((int)p_cur[i].status);
2386 p.writeInt32(p_cur[i].suggestedRetryTime);
2387 p.writeInt32(p_cur[i].cid);
2388 p.writeInt32(p_cur[i].active);
2389 writeStringToParcel(p, p_cur[i].type);
2390 writeStringToParcel(p, p_cur[i].ifname);
2391 writeStringToParcel(p, p_cur[i].addresses);
2392 writeStringToParcel(p, p_cur[i].dnses);
2393 writeStringToParcel(p, p_cur[i].gateways);
2394 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2395 p_cur[i].status,
2396 p_cur[i].suggestedRetryTime,
2397 p_cur[i].cid,
2398 (p_cur[i].active==0)?"down":"up",
2399 (char*)p_cur[i].type,
2400 (char*)p_cur[i].ifname,
2401 (char*)p_cur[i].addresses,
2402 (char*)p_cur[i].dnses,
2403 (char*)p_cur[i].gateways);
2404 }
2405 removeLastChar;
2406 closeResponse;
2407
2408 return 0;
2409}
2410
Wink Saville43808972011-01-13 17:39:51 -08002411static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2412{
Wink Saville43808972011-01-13 17:39:51 -08002413 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002414 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002415 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002416 } else {
2417 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002418 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002419 return RIL_ERRNO_INVALID_RESPONSE;
2420 }
2421
Etan Cohend3652192014-06-20 08:28:44 -07002422 // Support v6 or v9 with new rils
2423 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002424 RLOGD("responseDataCallList: v6");
Etan Cohend3652192014-06-20 08:28:44 -07002425 return responseDataCallListV6(p, response, responselen);
2426 }
2427
2428 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002429 RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002430 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002431 return RIL_ERRNO_INVALID_RESPONSE;
2432 }
2433
Amit Mahajan52500162014-07-29 17:36:48 -07002434 // Write version
2435 p.writeInt32(10);
2436
Etan Cohend3652192014-06-20 08:28:44 -07002437 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002438 p.writeInt32(num);
2439
Etan Cohend3652192014-06-20 08:28:44 -07002440 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002441 startResponse;
2442 int i;
2443 for (i = 0; i < num; i++) {
2444 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002445 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002446 p.writeInt32(p_cur[i].cid);
2447 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002448 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002449 writeStringToParcel(p, p_cur[i].ifname);
2450 writeStringToParcel(p, p_cur[i].addresses);
2451 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002452 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002453 writeStringToParcel(p, p_cur[i].pcscf);
2454 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002455 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002456 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002457 p_cur[i].cid,
2458 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002459 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002460 (char*)p_cur[i].ifname,
2461 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002462 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002463 (char*)p_cur[i].gateways,
2464 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002465 }
2466 removeLastChar;
2467 closeResponse;
2468 }
2469
2470 return 0;
2471}
2472
2473static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2474{
2475 if (s_callbacks.version < 5) {
2476 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2477 } else {
2478 return responseDataCallList(p, response, responselen);
2479 }
2480}
2481
Wink Savillef4c4d362009-04-02 01:37:03 -07002482static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002483 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002484 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002485 return RIL_ERRNO_INVALID_RESPONSE;
2486 }
2487
2488 // The java code reads -1 size as null byte array
2489 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002490 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002491 } else {
2492 p.writeInt32(responselen);
2493 p.write(response, responselen);
2494 }
2495
2496 return 0;
2497}
2498
2499
Wink Savillef4c4d362009-04-02 01:37:03 -07002500static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002501 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002502 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002503 return RIL_ERRNO_INVALID_RESPONSE;
2504 }
2505
2506 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002507 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002508 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2509 return RIL_ERRNO_INVALID_RESPONSE;
2510 }
2511
2512 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2513 p.writeInt32(p_cur->sw1);
2514 p.writeInt32(p_cur->sw2);
2515 writeStringToParcel(p, p_cur->simResponse);
2516
2517 startResponse;
2518 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2519 (char*)p_cur->simResponse);
2520 closeResponse;
2521
2522
2523 return 0;
2524}
2525
Wink Savillef4c4d362009-04-02 01:37:03 -07002526static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002527 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002528
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002529 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002530 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002531 return RIL_ERRNO_INVALID_RESPONSE;
2532 }
2533
2534 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002535 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002536 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2537 return RIL_ERRNO_INVALID_RESPONSE;
2538 }
2539
2540 /* number of call info's */
2541 num = responselen / sizeof(RIL_CallForwardInfo *);
2542 p.writeInt32(num);
2543
2544 startResponse;
2545 for (int i = 0 ; i < num ; i++) {
2546 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2547
2548 p.writeInt32(p_cur->status);
2549 p.writeInt32(p_cur->reason);
2550 p.writeInt32(p_cur->serviceClass);
2551 p.writeInt32(p_cur->toa);
2552 writeStringToParcel(p, p_cur->number);
2553 p.writeInt32(p_cur->timeSeconds);
2554 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2555 (p_cur->status==1)?"enable":"disable",
2556 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2557 (char*)p_cur->number,
2558 p_cur->timeSeconds);
2559 }
2560 removeLastChar;
2561 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002562
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002563 return 0;
2564}
2565
Wink Savillef4c4d362009-04-02 01:37:03 -07002566static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002567 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002568 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002569 return RIL_ERRNO_INVALID_RESPONSE;
2570 }
2571
2572 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002573 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002574 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2575 return RIL_ERRNO_INVALID_RESPONSE;
2576 }
2577
2578 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2579 p.writeInt32(p_cur->notificationType);
2580 p.writeInt32(p_cur->code);
2581 p.writeInt32(p_cur->index);
2582 p.writeInt32(p_cur->type);
2583 writeStringToParcel(p, p_cur->number);
2584
2585 startResponse;
2586 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2587 (p_cur->notificationType==0)?"mo":"mt",
2588 p_cur->code, p_cur->index, p_cur->type,
2589 (char*)p_cur->number);
2590 closeResponse;
2591
2592 return 0;
2593}
2594
Wink Saville3d54e742009-05-18 18:00:44 -07002595static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002596 int num;
2597
2598 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002599 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002600 return RIL_ERRNO_INVALID_RESPONSE;
2601 }
2602
2603 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002604 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002605 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2606 return RIL_ERRNO_INVALID_RESPONSE;
2607 }
2608
2609 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002610 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002611 num = responselen / sizeof(RIL_NeighboringCell *);
2612 p.writeInt32(num);
2613
2614 for (int i = 0 ; i < num ; i++) {
2615 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2616
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002617 p.writeInt32(p_cur->rssi);
2618 writeStringToParcel (p, p_cur->cid);
2619
2620 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2621 p_cur->cid, p_cur->rssi);
2622 }
2623 removeLastChar;
2624 closeResponse;
2625
2626 return 0;
2627}
2628
Wink Saville3d54e742009-05-18 18:00:44 -07002629/**
2630 * Marshall the signalInfoRecord into the parcel if it exists.
2631 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002632static void marshallSignalInfoRecord(Parcel &p,
2633 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002634 p.writeInt32(p_signalInfoRecord.isPresent);
2635 p.writeInt32(p_signalInfoRecord.signalType);
2636 p.writeInt32(p_signalInfoRecord.alertPitch);
2637 p.writeInt32(p_signalInfoRecord.signal);
2638}
2639
Wink Savillea592eeb2009-05-22 13:26:36 -07002640static int responseCdmaInformationRecords(Parcel &p,
2641 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002642 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002643 char* string8 = NULL;
2644 int buffer_lenght;
2645 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002646
2647 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002648 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002649 return RIL_ERRNO_INVALID_RESPONSE;
2650 }
2651
Wink Savillea592eeb2009-05-22 13:26:36 -07002652 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002653 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002654 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002655 return RIL_ERRNO_INVALID_RESPONSE;
2656 }
2657
Wink Savillea592eeb2009-05-22 13:26:36 -07002658 RIL_CDMA_InformationRecords *p_cur =
2659 (RIL_CDMA_InformationRecords *) response;
2660 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002661
2662 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002663 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002664
Wink Savillea592eeb2009-05-22 13:26:36 -07002665 for (int i = 0 ; i < num ; i++) {
2666 infoRec = &p_cur->infoRec[i];
2667 p.writeInt32(infoRec->name);
2668 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002669 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002670 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2671 if (infoRec->rec.display.alpha_len >
2672 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002673 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002674 expected not more than %d\n",
2675 (int)infoRec->rec.display.alpha_len,
2676 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2677 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002678 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002679 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2680 * sizeof(char) );
2681 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2682 string8[i] = infoRec->rec.display.alpha_buf[i];
2683 }
Wink Saville43808972011-01-13 17:39:51 -08002684 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002685 writeStringToParcel(p, (const char*)string8);
2686 free(string8);
2687 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002688 break;
2689 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002690 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002691 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002692 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002693 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002694 expected not more than %d\n",
2695 (int)infoRec->rec.number.len,
2696 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2697 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002698 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002699 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2700 * sizeof(char) );
2701 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2702 string8[i] = infoRec->rec.number.buf[i];
2703 }
Wink Saville43808972011-01-13 17:39:51 -08002704 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002705 writeStringToParcel(p, (const char*)string8);
2706 free(string8);
2707 string8 = NULL;
2708 p.writeInt32(infoRec->rec.number.number_type);
2709 p.writeInt32(infoRec->rec.number.number_plan);
2710 p.writeInt32(infoRec->rec.number.pi);
2711 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002712 break;
2713 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002714 p.writeInt32(infoRec->rec.signal.isPresent);
2715 p.writeInt32(infoRec->rec.signal.signalType);
2716 p.writeInt32(infoRec->rec.signal.alertPitch);
2717 p.writeInt32(infoRec->rec.signal.signal);
2718
2719 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2720 alertPitch=%X, signal=%X, ",
2721 printBuf, (int)infoRec->rec.signal.isPresent,
2722 (int)infoRec->rec.signal.signalType,
2723 (int)infoRec->rec.signal.alertPitch,
2724 (int)infoRec->rec.signal.signal);
2725 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002726 break;
2727 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002728 if (infoRec->rec.redir.redirectingNumber.len >
2729 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002730 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002731 expected not more than %d\n",
2732 (int)infoRec->rec.redir.redirectingNumber.len,
2733 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2734 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002735 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002736 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2737 .len + 1) * sizeof(char) );
2738 for (int i = 0;
2739 i < infoRec->rec.redir.redirectingNumber.len;
2740 i++) {
2741 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2742 }
Wink Saville43808972011-01-13 17:39:51 -08002743 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002744 writeStringToParcel(p, (const char*)string8);
2745 free(string8);
2746 string8 = NULL;
2747 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2748 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2749 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2750 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2751 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002752 break;
2753 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002754 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2755 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2756 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2757 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2758
2759 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2760 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2761 lineCtrlPowerDenial=%d, ", printBuf,
2762 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2763 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2764 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2765 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2766 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002767 break;
2768 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002769 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002770
Wink Savillea592eeb2009-05-22 13:26:36 -07002771 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2772 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002773 break;
2774 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002775 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2776 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2777
2778 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2779 infoRec->rec.audioCtrl.upLink,
2780 infoRec->rec.audioCtrl.downLink);
2781 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002782 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002783 case RIL_CDMA_T53_RELEASE_INFO_REC:
2784 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002785 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002786 return RIL_ERRNO_INVALID_RESPONSE;
2787 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002788 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002789 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002790 }
2791 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002792 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002793
Wink Savillea592eeb2009-05-22 13:26:36 -07002794 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002795}
2796
Wink Savillea592eeb2009-05-22 13:26:36 -07002797static int responseRilSignalStrength(Parcel &p,
2798 void *response, size_t responselen) {
2799 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002800 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002801 return RIL_ERRNO_INVALID_RESPONSE;
2802 }
2803
Wink Savillec0114b32011-02-18 10:14:07 -08002804 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002805 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002806
Wink Saville3d54e742009-05-18 18:00:44 -07002807 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2808 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2809 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2810 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2811 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2812 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2813 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002814 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002815 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002816 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002817 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002818 if (s_callbacks.version <= 6) {
2819 // signalStrength: -1 -> 99
2820 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2821 p_cur->LTE_SignalStrength.signalStrength = 99;
2822 }
2823 // rsrp: -1 -> INT_MAX all other negative value to positive.
2824 // So remap here
2825 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2826 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2827 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2828 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2829 }
2830 // rsrq: -1 -> INT_MAX
2831 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2832 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2833 }
2834 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002835
Wink Saville18e4ab12013-04-07 17:31:04 -07002836 // cqi: -1 -> INT_MAX
2837 if (p_cur->LTE_SignalStrength.cqi == -1) {
2838 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2839 }
2840 }
2841 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002842 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2843 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2844 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2845 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002846 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2847 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2848 } else {
2849 p.writeInt32(INT_MAX);
2850 }
Wink Savillec0114b32011-02-18 10:14:07 -08002851 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002852 p.writeInt32(99);
2853 p.writeInt32(INT_MAX);
2854 p.writeInt32(INT_MAX);
2855 p.writeInt32(INT_MAX);
2856 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002857 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002858 }
johnwangfdf825f2009-05-22 15:50:34 -07002859
2860 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002861 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002862 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2863 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2864 EVDO_SS.signalNoiseRatio=%d,\
2865 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002866 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002867 printBuf,
2868 p_cur->GW_SignalStrength.signalStrength,
2869 p_cur->GW_SignalStrength.bitErrorRate,
2870 p_cur->CDMA_SignalStrength.dbm,
2871 p_cur->CDMA_SignalStrength.ecio,
2872 p_cur->EVDO_SignalStrength.dbm,
2873 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002874 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2875 p_cur->LTE_SignalStrength.signalStrength,
2876 p_cur->LTE_SignalStrength.rsrp,
2877 p_cur->LTE_SignalStrength.rsrq,
2878 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002879 p_cur->LTE_SignalStrength.cqi,
2880 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002881 closeResponse;
2882
Wink Saville3d54e742009-05-18 18:00:44 -07002883 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002884 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002885 return RIL_ERRNO_INVALID_RESPONSE;
2886 }
2887
Wink Saville3d54e742009-05-18 18:00:44 -07002888 return 0;
2889}
2890
2891static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2892 if ((response == NULL) || (responselen == 0)) {
2893 return responseVoid(p, response, responselen);
2894 } else {
2895 return responseCdmaSignalInfoRecord(p, response, responselen);
2896 }
2897}
2898
2899static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2900 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002901 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002902 return RIL_ERRNO_INVALID_RESPONSE;
2903 }
2904
2905 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002906 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002907 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2908 return RIL_ERRNO_INVALID_RESPONSE;
2909 }
2910
2911 startResponse;
2912
2913 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2914 marshallSignalInfoRecord(p, *p_cur);
2915
2916 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2917 signal=%d]",
2918 printBuf,
2919 p_cur->isPresent,
2920 p_cur->signalType,
2921 p_cur->alertPitch,
2922 p_cur->signal);
2923
2924 closeResponse;
2925 return 0;
2926}
2927
Wink Savillea592eeb2009-05-22 13:26:36 -07002928static int responseCdmaCallWaiting(Parcel &p, void *response,
2929 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002930 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002931 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002932 return RIL_ERRNO_INVALID_RESPONSE;
2933 }
2934
Wink Savillec0114b32011-02-18 10:14:07 -08002935 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002936 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002937 }
2938
2939 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2940
2941 writeStringToParcel(p, p_cur->number);
2942 p.writeInt32(p_cur->numberPresentation);
2943 writeStringToParcel(p, p_cur->name);
2944 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2945
2946 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2947 p.writeInt32(p_cur->number_type);
2948 p.writeInt32(p_cur->number_plan);
2949 } else {
2950 p.writeInt32(0);
2951 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002952 }
2953
2954 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002955 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2956 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002957 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002958 printBuf,
2959 p_cur->number,
2960 p_cur->numberPresentation,
2961 p_cur->name,
2962 p_cur->signalInfoRecord.isPresent,
2963 p_cur->signalInfoRecord.signalType,
2964 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002965 p_cur->signalInfoRecord.signal,
2966 p_cur->number_type,
2967 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002968 closeResponse;
2969
2970 return 0;
2971}
2972
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002973static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2974 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002975 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002976 return RIL_ERRNO_INVALID_RESPONSE;
2977 }
2978
2979 startResponse;
2980 if (s_callbacks.version == 7) {
2981 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2982 p.writeInt32(p_cur->result);
2983 p.writeInt32(p_cur->ef_id);
2984 writeStringToParcel(p, p_cur->aid);
2985
2986 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2987 printBuf,
2988 p_cur->result,
2989 p_cur->ef_id,
2990 p_cur->aid);
2991 } else {
2992 int *p_cur = ((int *) response);
2993 p.writeInt32(p_cur[0]);
2994 p.writeInt32(p_cur[1]);
2995 writeStringToParcel(p, NULL);
2996
2997 appendPrintBuf("%sresult=%d, ef_id=%d",
2998 printBuf,
2999 p_cur[0],
3000 p_cur[1]);
3001 }
3002 closeResponse;
3003
3004 return 0;
3005}
3006
Wink Saville8a9e0212013-04-09 12:11:38 -07003007static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3008{
3009 if (response == NULL && responselen != 0) {
3010 RLOGE("invalid response: NULL");
3011 return RIL_ERRNO_INVALID_RESPONSE;
3012 }
3013
3014 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003015 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003016 (int)responselen, (int)sizeof(RIL_CellInfo));
3017 return RIL_ERRNO_INVALID_RESPONSE;
3018 }
3019
3020 int num = responselen / sizeof(RIL_CellInfo);
3021 p.writeInt32(num);
3022
3023 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3024 startResponse;
3025 int i;
3026 for (i = 0; i < num; i++) {
3027 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3028 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3029 p.writeInt32((int)p_cur->cellInfoType);
3030 p.writeInt32(p_cur->registered);
3031 p.writeInt32(p_cur->timeStampType);
3032 p.writeInt64(p_cur->timeStamp);
3033 switch(p_cur->cellInfoType) {
3034 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003035 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003036 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3037 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3038 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003039 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3040 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003041 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3042 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3043
3044 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3045 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3046 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3047 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003048 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3049 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3050 break;
3051 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003052 case RIL_CELL_INFO_TYPE_WCDMA: {
3053 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3054 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3055 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3056 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3057 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3058 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3059 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3060 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3061 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3062
3063 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3064 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3065 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3066 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3067 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3068 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3069 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3070 break;
3071 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003072 case RIL_CELL_INFO_TYPE_CDMA: {
3073 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3074 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3075 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3076 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3077 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3078 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3079
3080 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3081 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3082 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3083 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3084 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3085
3086 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3087 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3088 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3089 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3090 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3091 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3092
3093 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3094 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3095 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3096 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3097 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3098 break;
3099 }
3100 case RIL_CELL_INFO_TYPE_LTE: {
3101 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3102 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3103 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3104 p_cur->CellInfo.lte.cellIdentityLte.ci,
3105 p_cur->CellInfo.lte.cellIdentityLte.pci,
3106 p_cur->CellInfo.lte.cellIdentityLte.tac);
3107
3108 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3109 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3110 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3111 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3112 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3113
3114 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3115 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3116 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3117 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3118 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3119 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3120 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3121 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3122 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3123 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3124 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3125 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3126 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3127 break;
3128 }
Etan Cohend3652192014-06-20 08:28:44 -07003129 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3130 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3131 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3132 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3133 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3134 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3135 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3136 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3137 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3138
3139 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3140 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3141 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3142 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3143 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3144 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3145 break;
3146 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003147 }
3148 p_cur += 1;
3149 }
3150 removeLastChar;
3151 closeResponse;
3152
3153 return 0;
3154}
3155
Etan Cohend3652192014-06-20 08:28:44 -07003156static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3157{
3158 if (response == NULL && responselen != 0) {
3159 RLOGE("invalid response: NULL");
3160 return RIL_ERRNO_INVALID_RESPONSE;
3161 }
3162
3163 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003164 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003165 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3166 return RIL_ERRNO_INVALID_RESPONSE;
3167 }
3168
3169 int num = responselen / sizeof(RIL_HardwareConfig);
3170 int i;
3171 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3172
3173 p.writeInt32(num);
3174
3175 startResponse;
3176 for (i = 0; i < num; i++) {
3177 switch (p_cur[i].type) {
3178 case RIL_HARDWARE_CONFIG_MODEM: {
3179 writeStringToParcel(p, p_cur[i].uuid);
3180 p.writeInt32((int)p_cur[i].state);
3181 p.writeInt32(p_cur[i].cfg.modem.rat);
3182 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3183 p.writeInt32(p_cur[i].cfg.modem.maxData);
3184 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3185
3186 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3187 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3188 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3189 break;
3190 }
3191 case RIL_HARDWARE_CONFIG_SIM: {
3192 writeStringToParcel(p, p_cur[i].uuid);
3193 p.writeInt32((int)p_cur[i].state);
3194 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3195
3196 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3197 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3198 break;
3199 }
3200 }
3201 }
3202 removeLastChar;
3203 closeResponse;
3204 return 0;
3205}
3206
Wink Saville8b4e4f72014-10-17 15:01:45 -07003207static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3208 if (response == NULL) {
3209 RLOGE("invalid response: NULL");
3210 return RIL_ERRNO_INVALID_RESPONSE;
3211 }
3212
3213 if (responselen != sizeof (RIL_RadioCapability) ) {
3214 RLOGE("invalid response length was %d expected %d",
3215 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3216 return RIL_ERRNO_INVALID_RESPONSE;
3217 }
3218
3219 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3220 p.writeInt32(p_cur->version);
3221 p.writeInt32(p_cur->session);
3222 p.writeInt32(p_cur->phase);
3223 p.writeInt32(p_cur->rat);
3224 writeStringToParcel(p, p_cur->logicalModemUuid);
3225 p.writeInt32(p_cur->status);
3226
3227 startResponse;
3228 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003229 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003230 printBuf,
3231 p_cur->version,
3232 p_cur->session,
3233 p_cur->phase,
3234 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003235 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003236 p_cur->status);
3237 closeResponse;
3238 return 0;
3239}
3240
Wink Saville3d54e742009-05-18 18:00:44 -07003241static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003242 int ret;
3243 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3244 /* trigger event loop to wakeup. No reason to do this,
3245 * if we're in the event loop thread */
3246 do {
3247 ret = write (s_fdWakeupWrite, " ", 1);
3248 } while (ret < 0 && errno == EINTR);
3249 }
3250}
3251
Wink Saville3d54e742009-05-18 18:00:44 -07003252static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003253 ril_event_add(ev);
3254 triggerEvLoop();
3255}
3256
Wink Savillefd729372011-02-22 16:19:39 -08003257static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3258 p.writeInt32(num_apps);
3259 startResponse;
3260 for (int i = 0; i < num_apps; i++) {
3261 p.writeInt32(appStatus[i].app_type);
3262 p.writeInt32(appStatus[i].app_state);
3263 p.writeInt32(appStatus[i].perso_substate);
3264 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3265 writeStringToParcel(p, (const char*)
3266 (appStatus[i].app_label_ptr));
3267 p.writeInt32(appStatus[i].pin1_replaced);
3268 p.writeInt32(appStatus[i].pin1);
3269 p.writeInt32(appStatus[i].pin2);
3270 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3271 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3272 printBuf,
3273 appStatus[i].app_type,
3274 appStatus[i].app_state,
3275 appStatus[i].perso_substate,
3276 appStatus[i].aid_ptr,
3277 appStatus[i].app_label_ptr,
3278 appStatus[i].pin1_replaced,
3279 appStatus[i].pin1,
3280 appStatus[i].pin2);
3281 }
3282 closeResponse;
3283}
3284
Wink Savillef4c4d362009-04-02 01:37:03 -07003285static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3286 int i;
3287
3288 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003289 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003290 return RIL_ERRNO_INVALID_RESPONSE;
3291 }
3292
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003293 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003294 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003295
Wink Savillefd729372011-02-22 16:19:39 -08003296 p.writeInt32(p_cur->card_state);
3297 p.writeInt32(p_cur->universal_pin_state);
3298 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3299 p.writeInt32(p_cur->cdma_subscription_app_index);
3300 p.writeInt32(p_cur->ims_subscription_app_index);
3301
3302 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003303 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003304 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3305
3306 p.writeInt32(p_cur->card_state);
3307 p.writeInt32(p_cur->universal_pin_state);
3308 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3309 p.writeInt32(p_cur->cdma_subscription_app_index);
3310 p.writeInt32(-1);
3311
3312 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003313 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003314 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003315 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003316 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003317
3318 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003319}
Wink Savillef4c4d362009-04-02 01:37:03 -07003320
Wink Savillea592eeb2009-05-22 13:26:36 -07003321static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3322 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003323 p.writeInt32(num);
3324
Wink Savillef4c4d362009-04-02 01:37:03 -07003325 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003326 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3327 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3328 for (int i = 0; i < num; i++) {
3329 p.writeInt32(p_cur[i]->fromServiceId);
3330 p.writeInt32(p_cur[i]->toServiceId);
3331 p.writeInt32(p_cur[i]->fromCodeScheme);
3332 p.writeInt32(p_cur[i]->toCodeScheme);
3333 p.writeInt32(p_cur[i]->selected);
3334
3335 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3336 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3337 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3338 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3339 p_cur[i]->selected);
3340 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003341 closeResponse;
3342
3343 return 0;
3344}
3345
Wink Savillea592eeb2009-05-22 13:26:36 -07003346static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3347 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3348 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003349
Wink Savillea592eeb2009-05-22 13:26:36 -07003350 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3351 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003352
3353 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003354 for (int i = 0 ; i < num ; i++ ) {
3355 p.writeInt32(p_cur[i]->service_category);
3356 p.writeInt32(p_cur[i]->language);
3357 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003358
Wink Savillea592eeb2009-05-22 13:26:36 -07003359 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3360 selected =%d], ",
3361 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3362 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003363 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003364 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003365
Wink Savillef4c4d362009-04-02 01:37:03 -07003366 return 0;
3367}
3368
3369static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3370 int num;
3371 int digitCount;
3372 int digitLimit;
3373 uint8_t uct;
3374 void* dest;
3375
Wink Saville8eb2a122012-11-19 16:05:13 -08003376 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003377
Wink Savillef4c4d362009-04-02 01:37:03 -07003378 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003379 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003380 return RIL_ERRNO_INVALID_RESPONSE;
3381 }
3382
Wink Savillef5903df2009-04-24 11:54:14 -07003383 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003384 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003385 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003386 return RIL_ERRNO_INVALID_RESPONSE;
3387 }
3388
3389 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3390 p.writeInt32(p_cur->uTeleserviceID);
3391 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3392 p.writeInt32(p_cur->uServicecategory);
3393 p.writeInt32(p_cur->sAddress.digit_mode);
3394 p.writeInt32(p_cur->sAddress.number_mode);
3395 p.writeInt32(p_cur->sAddress.number_type);
3396 p.writeInt32(p_cur->sAddress.number_plan);
3397 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3398 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3399 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3400 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3401 }
3402
3403 p.writeInt32(p_cur->sSubAddress.subaddressType);
3404 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3405 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3406 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3407 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3408 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3409 }
3410
3411 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3412 p.writeInt32(p_cur->uBearerDataLen);
3413 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3414 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3415 }
3416
3417 startResponse;
3418 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003419 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003420 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3421 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3422 closeResponse;
3423
3424 return 0;
3425}
3426
Wink Savillec29360a2014-07-13 05:17:28 -07003427static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3428{
3429 int num = responselen / sizeof(RIL_DcRtInfo);
3430 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003431 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003432 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3433 return RIL_ERRNO_INVALID_RESPONSE;
3434 }
3435
3436 startResponse;
3437 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3438 p.writeInt64(pDcRtInfo->time);
3439 p.writeInt32(pDcRtInfo->powerState);
3440 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3441 pDcRtInfo->time,
3442 pDcRtInfo->powerState);
3443 closeResponse;
3444
3445 return 0;
3446}
3447
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003448/**
3449 * A write on the wakeup fd is done just to pop us out of select()
3450 * We empty the buffer here and then ril_event will reset the timers on the
3451 * way back down
3452 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003453static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003454 char buff[16];
3455 int ret;
3456
Wink Saville8eb2a122012-11-19 16:05:13 -08003457 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003458
3459 /* empty our wakeup socket out */
3460 do {
3461 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003462 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003463}
3464
Etan Cohend3652192014-06-20 08:28:44 -07003465static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003466 int ret;
3467 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003468 /* Hook for current context
3469 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3470 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3471 /* pendingRequestsHook refer to &s_pendingRequests */
3472 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003473
Etan Cohend3652192014-06-20 08:28:44 -07003474#if (SIM_COUNT >= 2)
3475 if (socket_id == RIL_SOCKET_2) {
3476 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3477 pendingRequestsHook = &s_pendingRequests_socket2;
3478 }
3479#if (SIM_COUNT >= 3)
3480 else if (socket_id == RIL_SOCKET_3) {
3481 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3482 pendingRequestsHook = &s_pendingRequests_socket3;
3483 }
3484#endif
3485#if (SIM_COUNT >= 4)
3486 else if (socket_id == RIL_SOCKET_4) {
3487 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3488 pendingRequestsHook = &s_pendingRequests_socket4;
3489 }
3490#endif
3491#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003492 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003493 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003494 assert (ret == 0);
3495
Etan Cohend3652192014-06-20 08:28:44 -07003496 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003497
Etan Cohend3652192014-06-20 08:28:44 -07003498 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003499 ; p_cur != NULL
3500 ; p_cur = p_cur->p_next
3501 ) {
3502 p_cur->cancelled = 1;
3503 }
3504
Etan Cohend3652192014-06-20 08:28:44 -07003505 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003506 assert (ret == 0);
3507}
3508
Wink Savillef4c4d362009-04-02 01:37:03 -07003509static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003510 RecordStream *p_rs;
3511 void *p_record;
3512 size_t recordlen;
3513 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003514 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003515
Etan Cohend3652192014-06-20 08:28:44 -07003516 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003517
Etan Cohend3652192014-06-20 08:28:44 -07003518 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003519
3520 for (;;) {
3521 /* loop until EAGAIN/EINTR, end of stream, or other error */
3522 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3523
3524 if (ret == 0 && p_record == NULL) {
3525 /* end-of-stream */
3526 break;
3527 } else if (ret < 0) {
3528 break;
3529 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003530 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003531 }
3532 }
3533
3534 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3535 /* fatal error or end-of-stream */
3536 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003537 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003538 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003539 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003540 }
Wink Saville7f856802009-06-09 10:23:37 -07003541
Etan Cohend3652192014-06-20 08:28:44 -07003542 close(fd);
3543 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003544
Etan Cohend3652192014-06-20 08:28:44 -07003545 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003546
3547 record_stream_free(p_rs);
3548
3549 /* start listening for new connections again */
3550 rilEventAddWakeup(&s_listen_event);
3551
Etan Cohend3652192014-06-20 08:28:44 -07003552 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003553 }
3554}
3555
3556
Etan Cohend3652192014-06-20 08:28:44 -07003557static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003558 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003559 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003560 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3561 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003562
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003563 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003564 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3565 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003566
3567 // Send last NITZ time data, in case it was missed
3568 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003569 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003570
3571 free(s_lastNITZTimeData);
3572 s_lastNITZTimeData = NULL;
3573 }
3574
3575 // Get version string
3576 if (s_callbacks.getVersion != NULL) {
3577 const char *version;
3578 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003579 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003580
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003581 property_set(PROPERTY_RIL_IMPL, version);
3582 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003583 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003584 property_set(PROPERTY_RIL_IMPL, "unavailable");
3585 }
3586
3587}
3588
Wink Savillef4c4d362009-04-02 01:37:03 -07003589static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003590 int ret;
3591 int err;
3592 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003593 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003594 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003595 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003596
3597 struct sockaddr_un peeraddr;
3598 socklen_t socklen = sizeof (peeraddr);
3599
3600 struct ucred creds;
3601 socklen_t szCreds = sizeof(creds);
3602
3603 struct passwd *pwd = NULL;
3604
Etan Cohend3652192014-06-20 08:28:44 -07003605 assert (*p_info->fdCommand < 0);
3606 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003607
Etan Cohend3652192014-06-20 08:28:44 -07003608 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003609
Etan Cohend3652192014-06-20 08:28:44 -07003610 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003611 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003612 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003613 rilEventAddWakeup(p_info->listen_event);
3614 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003615 }
3616
3617 /* check the credential of the other side and only accept socket from
3618 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003619 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003620 errno = 0;
3621 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003622
Etan Cohend3652192014-06-20 08:28:44 -07003623 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003624
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003625 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003626 errno = 0;
3627 pwd = getpwuid(creds.uid);
3628 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003629 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003630 is_phone_socket = 1;
3631 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003632 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003633 }
3634 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003635 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003636 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003637 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003638 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003639 }
3640
Etan Cohend3652192014-06-20 08:28:44 -07003641 if (!is_phone_socket) {
3642 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003643
Etan Cohend3652192014-06-20 08:28:44 -07003644 close(fdCommand);
3645 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003646
Etan Cohend3652192014-06-20 08:28:44 -07003647 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003648
3649 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003650 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003651
3652 return;
3653 }
3654
Etan Cohend3652192014-06-20 08:28:44 -07003655 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003656
3657 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003658 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003659 }
3660
Etan Cohend3652192014-06-20 08:28:44 -07003661 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003662
Etan Cohend3652192014-06-20 08:28:44 -07003663 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003664
Etan Cohend3652192014-06-20 08:28:44 -07003665 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003666
Etan Cohend3652192014-06-20 08:28:44 -07003667 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003668
Etan Cohend3652192014-06-20 08:28:44 -07003669 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3670 p_info->processCommandsCallback, p_info);
3671
3672 rilEventAddWakeup (p_info->commands_event);
3673
3674 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003675}
3676
3677static void freeDebugCallbackArgs(int number, char **args) {
3678 for (int i = 0; i < number; i++) {
3679 if (args[i] != NULL) {
3680 free(args[i]);
3681 }
3682 }
3683 free(args);
3684}
3685
Wink Savillef4c4d362009-04-02 01:37:03 -07003686static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003687 int acceptFD, option;
3688 struct sockaddr_un peeraddr;
3689 socklen_t socklen = sizeof (peeraddr);
3690 int data;
3691 unsigned int qxdm_data[6];
3692 const char *deactData[1] = {"1"};
3693 char *actData[1];
3694 RIL_Dial dialData;
3695 int hangupData[1] = {1};
3696 int number;
3697 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003698 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3699 int sim_id = 0;
3700
3701 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003702
3703 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3704
3705 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003706 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003707 return;
3708 }
3709
3710 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003711 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003712 return;
3713 }
3714 args = (char **) malloc(sizeof(char*) * number);
3715
3716 for (int i = 0; i < number; i++) {
3717 int len;
3718 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003719 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003720 freeDebugCallbackArgs(i, args);
3721 return;
3722 }
3723 // +1 for null-term
3724 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003725 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003726 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003727 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003728 freeDebugCallbackArgs(i, args);
3729 return;
3730 }
3731 char * buf = args[i];
3732 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003733 if ((i+1) == number) {
3734 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3735 sim_id = atoi(args[i]);
3736 switch (sim_id) {
3737 case 0:
3738 socket_id = RIL_SOCKET_1;
3739 break;
3740 #if (SIM_COUNT >= 2)
3741 case 1:
3742 socket_id = RIL_SOCKET_2;
3743 break;
3744 #endif
3745 #if (SIM_COUNT >= 3)
3746 case 2:
3747 socket_id = RIL_SOCKET_3;
3748 break;
3749 #endif
3750 #if (SIM_COUNT >= 4)
3751 case 3:
3752 socket_id = RIL_SOCKET_4;
3753 break;
3754 #endif
3755 default:
3756 socket_id = RIL_SOCKET_1;
3757 break;
3758 }
3759 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003760 }
3761
3762 switch (atoi(args[0])) {
3763 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003764 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003765 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003766 break;
3767 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003768 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003769 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003770 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003771 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003772 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3773 close(s_ril_param_socket.fdCommand);
3774 s_ril_param_socket.fdCommand = -1;
3775 }
3776 #if (SIM_COUNT == 2)
3777 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3778 close(s_ril_param_socket2.fdCommand);
3779 s_ril_param_socket2.fdCommand = -1;
3780 }
3781 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003782 break;
3783 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003784 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003785 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003786 break;
3787 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003788 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003789 qxdm_data[0] = 65536; // head.func_tag
3790 qxdm_data[1] = 16; // head.len
3791 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3792 qxdm_data[3] = 32; // log_file_size: 32megabytes
3793 qxdm_data[4] = 0; // log_mask
3794 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003795 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003796 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003797 break;
3798 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003799 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003800 qxdm_data[0] = 65536;
3801 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003802 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003803 qxdm_data[3] = 32;
3804 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003805 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003806 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003807 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003808 break;
3809 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003810 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003811 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003812 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003813 sleep(2);
3814 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003815 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003816 break;
3817 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003818 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003820 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003821 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003822 break;
3823 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003824 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003825 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003826 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003827 break;
3828 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003829 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003830 dialData.clir = 0;
3831 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003832 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003833 break;
3834 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003835 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003836 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003837 break;
3838 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003839 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003840 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003841 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003842 break;
3843 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003844 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003845 break;
3846 }
3847 freeDebugCallbackArgs(number, args);
3848 close(acceptFD);
3849}
3850
3851
Wink Savillef4c4d362009-04-02 01:37:03 -07003852static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003853 UserCallbackInfo *p_info;
3854
3855 p_info = (UserCallbackInfo *)param;
3856
3857 p_info->p_callback(p_info->userParam);
3858
3859
3860 // FIXME generalize this...there should be a cancel mechanism
3861 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3862 s_last_wake_timeout_info = NULL;
3863 }
3864
3865 free(p_info);
3866}
3867
3868
3869static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003870eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003871 int ret;
3872 int filedes[2];
3873
3874 ril_event_init();
3875
3876 pthread_mutex_lock(&s_startupMutex);
3877
3878 s_started = 1;
3879 pthread_cond_broadcast(&s_startupCond);
3880
3881 pthread_mutex_unlock(&s_startupMutex);
3882
3883 ret = pipe(filedes);
3884
3885 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003886 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003887 return NULL;
3888 }
3889
3890 s_fdWakeupRead = filedes[0];
3891 s_fdWakeupWrite = filedes[1];
3892
3893 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3894
3895 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3896 processWakeupCallback, NULL);
3897
3898 rilEventAddWakeup (&s_wakeupfd_event);
3899
3900 // Only returns on error
3901 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003902 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003903 // kill self to restart on error
3904 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003905
3906 return NULL;
3907}
3908
Wink Saville7f856802009-06-09 10:23:37 -07003909extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003910RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003911 /* spin up eventLoop thread and wait for it to get started */
3912 s_started = 0;
3913 pthread_mutex_lock(&s_startupMutex);
3914
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003915 pthread_attr_t attr;
3916 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003917 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003918
Elliott Hughesfd81e712014-01-06 12:46:02 -08003919 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3920 if (result != 0) {
3921 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003922 goto done;
3923 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003924
3925 while (s_started == 0) {
3926 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3927 }
3928
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003929done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003930 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003931}
3932
3933// Used for testing purpose only.
3934extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3935 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3936}
3937
Etan Cohend3652192014-06-20 08:28:44 -07003938static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3939 int fdListen = -1;
3940 int ret;
3941 char socket_name[10];
3942
3943 memset(socket_name, 0, sizeof(char)*10);
3944
3945 switch(socket_id) {
3946 case RIL_SOCKET_1:
3947 strncpy(socket_name, RIL_getRilSocketName(), 9);
3948 break;
3949 #if (SIM_COUNT >= 2)
3950 case RIL_SOCKET_2:
3951 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3952 break;
3953 #endif
3954 #if (SIM_COUNT >= 3)
3955 case RIL_SOCKET_3:
3956 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3957 break;
3958 #endif
3959 #if (SIM_COUNT >= 4)
3960 case RIL_SOCKET_4:
3961 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3962 break;
3963 #endif
3964 default:
3965 RLOGE("Socket id is wrong!!");
3966 return;
3967 }
3968
3969 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3970
3971 fdListen = android_get_control_socket(socket_name);
3972 if (fdListen < 0) {
3973 RLOGE("Failed to get socket %s", socket_name);
3974 exit(-1);
3975 }
3976
3977 ret = listen(fdListen, 4);
3978
3979 if (ret < 0) {
3980 RLOGE("Failed to listen on control socket '%d': %s",
3981 fdListen, strerror(errno));
3982 exit(-1);
3983 }
3984 socket_listen_p->fdListen = fdListen;
3985
3986 /* note: non-persistent so we can accept only one connection at a time */
3987 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3988 listenCallback, socket_listen_p);
3989
3990 rilEventAddWakeup (socket_listen_p->listen_event);
3991}
3992
Wink Saville7f856802009-06-09 10:23:37 -07003993extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003994RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003995 int ret;
3996 int flags;
3997
Etan Cohend3652192014-06-20 08:28:44 -07003998 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3999
Wink Saville43808972011-01-13 17:39:51 -08004000 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004001 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004002 return;
4003 }
Wink Saville43808972011-01-13 17:39:51 -08004004 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004005 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004006 callbacks->version, RIL_VERSION_MIN);
4007 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004008 }
Wink Saville43808972011-01-13 17:39:51 -08004009 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004010 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004011 callbacks->version, RIL_VERSION);
4012 return;
4013 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004014 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004015
4016 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004017 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004018 "Subsequent call ignored");
4019 return;
4020 }
4021
4022 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4023
Etan Cohend3652192014-06-20 08:28:44 -07004024 /* Initialize socket1 parameters */
4025 s_ril_param_socket = {
4026 RIL_SOCKET_1, /* socket_id */
4027 -1, /* fdListen */
4028 -1, /* fdCommand */
4029 PHONE_PROCESS, /* processName */
4030 &s_commands_event, /* commands_event */
4031 &s_listen_event, /* listen_event */
4032 processCommandsCallback, /* processCommandsCallback */
4033 NULL /* p_rs */
4034 };
4035
4036#if (SIM_COUNT >= 2)
4037 s_ril_param_socket2 = {
4038 RIL_SOCKET_2, /* socket_id */
4039 -1, /* fdListen */
4040 -1, /* fdCommand */
4041 PHONE_PROCESS, /* processName */
4042 &s_commands_event_socket2, /* commands_event */
4043 &s_listen_event_socket2, /* listen_event */
4044 processCommandsCallback, /* processCommandsCallback */
4045 NULL /* p_rs */
4046 };
4047#endif
4048
4049#if (SIM_COUNT >= 3)
4050 s_ril_param_socket3 = {
4051 RIL_SOCKET_3, /* socket_id */
4052 -1, /* fdListen */
4053 -1, /* fdCommand */
4054 PHONE_PROCESS, /* processName */
4055 &s_commands_event_socket3, /* commands_event */
4056 &s_listen_event_socket3, /* listen_event */
4057 processCommandsCallback, /* processCommandsCallback */
4058 NULL /* p_rs */
4059 };
4060#endif
4061
4062#if (SIM_COUNT >= 4)
4063 s_ril_param_socket4 = {
4064 RIL_SOCKET_4, /* socket_id */
4065 -1, /* fdListen */
4066 -1, /* fdCommand */
4067 PHONE_PROCESS, /* processName */
4068 &s_commands_event_socket4, /* commands_event */
4069 &s_listen_event_socket4, /* listen_event */
4070 processCommandsCallback, /* processCommandsCallback */
4071 NULL /* p_rs */
4072 };
4073#endif
4074
4075
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004076 s_registerCalled = 1;
4077
Etan Cohend3652192014-06-20 08:28:44 -07004078 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004079 // Little self-check
4080
Wink Savillef4c4d362009-04-02 01:37:03 -07004081 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004082 assert(i == s_commands[i].requestNumber);
4083 }
4084
Wink Savillef4c4d362009-04-02 01:37:03 -07004085 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004086 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004087 == s_unsolResponses[i].requestNumber);
4088 }
4089
4090 // New rild impl calls RIL_startEventLoop() first
4091 // old standalone impl wants it here.
4092
4093 if (s_started == 0) {
4094 RIL_startEventLoop();
4095 }
4096
Etan Cohend3652192014-06-20 08:28:44 -07004097 // start listen socket1
4098 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004099
Etan Cohend3652192014-06-20 08:28:44 -07004100#if (SIM_COUNT >= 2)
4101 // start listen socket2
4102 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4103#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004104
Etan Cohend3652192014-06-20 08:28:44 -07004105#if (SIM_COUNT >= 3)
4106 // start listen socket3
4107 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4108#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004109
Etan Cohend3652192014-06-20 08:28:44 -07004110#if (SIM_COUNT >= 4)
4111 // start listen socket4
4112 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4113#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004114
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004115
4116#if 1
4117 // start debug interface socket
4118
Etan Cohend3652192014-06-20 08:28:44 -07004119 char *inst = NULL;
4120 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4121 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4122 }
4123
4124 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4125 if (inst != NULL) {
4126 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4127 }
4128
4129 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004130 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004131 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004132 exit(-1);
4133 }
4134
4135 ret = listen(s_fdDebug, 4);
4136
4137 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004138 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004139 s_fdDebug, strerror(errno));
4140 exit(-1);
4141 }
4142
4143 ril_event_set (&s_debug_event, s_fdDebug, true,
4144 debugCallback, NULL);
4145
4146 rilEventAddWakeup (&s_debug_event);
4147#endif
4148
4149}
4150
4151static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004152checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004153 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004154 /* Hook for current context
4155 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4156 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4157 /* pendingRequestsHook refer to &s_pendingRequests */
4158 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004159
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004160 if (pRI == NULL) {
4161 return 0;
4162 }
4163
Etan Cohend3652192014-06-20 08:28:44 -07004164#if (SIM_COUNT >= 2)
4165 if (pRI->socket_id == RIL_SOCKET_2) {
4166 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4167 pendingRequestsHook = &s_pendingRequests_socket2;
4168 }
4169#if (SIM_COUNT >= 3)
4170 if (pRI->socket_id == RIL_SOCKET_3) {
4171 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4172 pendingRequestsHook = &s_pendingRequests_socket3;
4173 }
4174#endif
4175#if (SIM_COUNT >= 4)
4176 if (pRI->socket_id == RIL_SOCKET_4) {
4177 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4178 pendingRequestsHook = &s_pendingRequests_socket4;
4179 }
4180#endif
4181#endif
4182 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004183
Etan Cohend3652192014-06-20 08:28:44 -07004184 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004185 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004186 ; ppCur = &((*ppCur)->p_next)
4187 ) {
4188 if (pRI == *ppCur) {
4189 ret = 1;
4190
4191 *ppCur = (*ppCur)->p_next;
4192 break;
4193 }
4194 }
4195
Etan Cohend3652192014-06-20 08:28:44 -07004196 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004197
4198 return ret;
4199}
4200
4201
4202extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004203RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004204 RequestInfo *pRI;
4205 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004206 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004207 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004208 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004209
4210 pRI = (RequestInfo *)t;
4211
Jayachandran C6c607592014-08-04 15:48:01 -07004212 if (!checkAndDequeueRequestInfo(pRI)) {
4213 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4214 return;
4215 }
4216
Etan Cohend3652192014-06-20 08:28:44 -07004217 socket_id = pRI->socket_id;
4218#if (SIM_COUNT >= 2)
4219 if (socket_id == RIL_SOCKET_2) {
4220 fd = s_ril_param_socket2.fdCommand;
4221 }
4222#if (SIM_COUNT >= 3)
4223 if (socket_id == RIL_SOCKET_3) {
4224 fd = s_ril_param_socket3.fdCommand;
4225 }
4226#endif
4227#if (SIM_COUNT >= 4)
4228 if (socket_id == RIL_SOCKET_4) {
4229 fd = s_ril_param_socket4.fdCommand;
4230 }
4231#endif
4232#endif
4233 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4234
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235 if (pRI->local > 0) {
4236 // Locally issued command...void only!
4237 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004238 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004239
4240 goto done;
4241 }
4242
4243 appendPrintBuf("[%04d]< %s",
4244 pRI->token, requestToString(pRI->pCI->requestNumber));
4245
4246 if (pRI->cancelled == 0) {
4247 Parcel p;
4248
4249 p.writeInt32 (RESPONSE_SOLICITED);
4250 p.writeInt32 (pRI->token);
4251 errorOffset = p.dataPosition();
4252
4253 p.writeInt32 (e);
4254
johnwangb2a61842009-06-02 14:55:45 -07004255 if (response != NULL) {
4256 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004257 ret = pRI->pCI->responseFunction(p, response, responselen);
4258
4259 /* if an error occurred, rewind and mark it */
4260 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004261 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004262 p.setDataPosition(errorOffset);
4263 p.writeInt32 (ret);
4264 }
johnwangb2a61842009-06-02 14:55:45 -07004265 }
4266
4267 if (e != RIL_E_SUCCESS) {
4268 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004269 }
4270
Etan Cohend3652192014-06-20 08:28:44 -07004271 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004272 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004273 }
Etan Cohend3652192014-06-20 08:28:44 -07004274 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004275 }
4276
4277done:
4278 free(pRI);
4279}
4280
4281
4282static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004283grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004284 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4285}
4286
4287static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004288releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004289 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4290}
4291
4292/**
4293 * Timer callback to put us back to sleep before the default timeout
4294 */
4295static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004296wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004297 // We're using "param != NULL" as a cancellation mechanism
4298 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004299 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004300
4301 releaseWakeLock();
4302 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004303 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004304 }
4305}
4306
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004307static int
4308decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4309 switch (radioState) {
4310 case RADIO_STATE_SIM_NOT_READY:
4311 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4312 case RADIO_STATE_SIM_READY:
4313 return RADIO_TECH_UMTS;
4314
4315 case RADIO_STATE_RUIM_NOT_READY:
4316 case RADIO_STATE_RUIM_READY:
4317 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4318 case RADIO_STATE_NV_NOT_READY:
4319 case RADIO_STATE_NV_READY:
4320 return RADIO_TECH_1xRTT;
4321
4322 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004323 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004324 return -1;
4325 }
4326}
4327
4328static int
4329decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4330 switch (radioState) {
4331 case RADIO_STATE_SIM_NOT_READY:
4332 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4333 case RADIO_STATE_SIM_READY:
4334 case RADIO_STATE_RUIM_NOT_READY:
4335 case RADIO_STATE_RUIM_READY:
4336 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4337 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4338
4339 case RADIO_STATE_NV_NOT_READY:
4340 case RADIO_STATE_NV_READY:
4341 return CDMA_SUBSCRIPTION_SOURCE_NV;
4342
4343 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004344 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004345 return -1;
4346 }
4347}
4348
4349static int
4350decodeSimStatus (RIL_RadioState radioState) {
4351 switch (radioState) {
4352 case RADIO_STATE_SIM_NOT_READY:
4353 case RADIO_STATE_RUIM_NOT_READY:
4354 case RADIO_STATE_NV_NOT_READY:
4355 case RADIO_STATE_NV_READY:
4356 return -1;
4357 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4358 case RADIO_STATE_SIM_READY:
4359 case RADIO_STATE_RUIM_READY:
4360 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4361 return radioState;
4362 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004363 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004364 return -1;
4365 }
4366}
4367
4368static bool is3gpp2(int radioTech) {
4369 switch (radioTech) {
4370 case RADIO_TECH_IS95A:
4371 case RADIO_TECH_IS95B:
4372 case RADIO_TECH_1xRTT:
4373 case RADIO_TECH_EVDO_0:
4374 case RADIO_TECH_EVDO_A:
4375 case RADIO_TECH_EVDO_B:
4376 case RADIO_TECH_EHRPD:
4377 return true;
4378 default:
4379 return false;
4380 }
4381}
4382
4383/* If RIL sends SIM states or RUIM states, store the voice radio
4384 * technology and subscription source information so that they can be
4385 * returned when telephony framework requests them
4386 */
4387static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004388processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004389
4390 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4391 int newVoiceRadioTech;
4392 int newCdmaSubscriptionSource;
4393 int newSimStatus;
4394
4395 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4396 from Radio State and send change notifications if there has been a change */
4397 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4398 if(newVoiceRadioTech != voiceRadioTech) {
4399 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004400 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4401 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004402 }
4403 if(is3gpp2(newVoiceRadioTech)) {
4404 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4405 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4406 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004407 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4408 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004409 }
4410 }
4411 newSimStatus = decodeSimStatus(newRadioState);
4412 if(newSimStatus != simRuimStatus) {
4413 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004414 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004415 }
4416
4417 /* Send RADIO_ON to telephony */
4418 newRadioState = RADIO_STATE_ON;
4419 }
4420
4421 return newRadioState;
4422}
4423
Etan Cohend3652192014-06-20 08:28:44 -07004424
4425#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004426extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004427void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4428 size_t datalen, RIL_SOCKET_ID socket_id)
4429#else
4430extern "C"
4431void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004432 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004433#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004434{
4435 int unsolResponseIndex;
4436 int ret;
4437 int64_t timeReceived = 0;
4438 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004439 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004440 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4441
4442#if defined(ANDROID_MULTI_SIM)
4443 soc_id = socket_id;
4444#endif
4445
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004446
4447 if (s_registerCalled == 0) {
4448 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004449 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004450 return;
4451 }
Wink Saville7f856802009-06-09 10:23:37 -07004452
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004453 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4454
4455 if ((unsolResponseIndex < 0)
4456 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004457 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004458 return;
4459 }
4460
4461 // Grab a wake lock if needed for this reponse,
4462 // as we exit we'll either release it immediately
4463 // or set a timer to release it later.
4464 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4465 case WAKE_PARTIAL:
4466 grabPartialWakeLock();
4467 shouldScheduleTimeout = true;
4468 break;
4469
4470 case DONT_WAKE:
4471 default:
4472 // No wake lock is grabed so don't set timeout
4473 shouldScheduleTimeout = false;
4474 break;
4475 }
4476
4477 // Mark the time this was received, doing this
4478 // after grabing the wakelock incase getting
4479 // the elapsedRealTime might cause us to goto
4480 // sleep.
4481 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4482 timeReceived = elapsedRealtime();
4483 }
4484
4485 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4486
4487 Parcel p;
4488
4489 p.writeInt32 (RESPONSE_UNSOLICITED);
4490 p.writeInt32 (unsolResponse);
4491
4492 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004493 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004494 if (ret != 0) {
4495 // Problem with the response. Don't continue;
4496 goto error_exit;
4497 }
4498
4499 // some things get more payload
4500 switch(unsolResponse) {
4501 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004502 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004503 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004504 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004505 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004506 break;
4507
4508
4509 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4510 // Store the time that this was received so the
4511 // handler of this message can account for
4512 // the time it takes to arrive and process. In
4513 // particular the system has been known to sleep
4514 // before this message can be processed.
4515 p.writeInt64(timeReceived);
4516 break;
4517 }
4518
Etan Cohend3652192014-06-20 08:28:44 -07004519 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4520 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004521 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4522
4523 // Unfortunately, NITZ time is not poll/update like everything
4524 // else in the system. So, if the upstream client isn't connected,
4525 // keep a copy of the last NITZ response (with receive time noted
4526 // above) around so we can deliver it when it is connected
4527
4528 if (s_lastNITZTimeData != NULL) {
4529 free (s_lastNITZTimeData);
4530 s_lastNITZTimeData = NULL;
4531 }
4532
4533 s_lastNITZTimeData = malloc(p.dataSize());
4534 s_lastNITZTimeDataSize = p.dataSize();
4535 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4536 }
4537
4538 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4539 // FIXME The java code should handshake here to release wake lock
4540
4541 if (shouldScheduleTimeout) {
4542 // Cancel the previous request
4543 if (s_last_wake_timeout_info != NULL) {
4544 s_last_wake_timeout_info->userParam = (void *)1;
4545 }
4546
4547 s_last_wake_timeout_info
4548 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4549 &TIMEVAL_WAKE_TIMEOUT);
4550 }
4551
4552 // Normal exit
4553 return;
4554
4555error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004556 if (shouldScheduleTimeout) {
4557 releaseWakeLock();
4558 }
4559}
4560
Wink Saville7f856802009-06-09 10:23:37 -07004561/** FIXME generalize this if you track UserCAllbackInfo, clear it
4562 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004563*/
4564static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004565internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004566 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004567{
4568 struct timeval myRelativeTime;
4569 UserCallbackInfo *p_info;
4570
4571 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4572
Wink Saville7f856802009-06-09 10:23:37 -07004573 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004574 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004575
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004576 if (relativeTime == NULL) {
4577 /* treat null parameter as a 0 relative time */
4578 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4579 } else {
4580 /* FIXME I think event_add's tv param is really const anyway */
4581 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4582 }
4583
4584 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4585
4586 ril_timer_add(&(p_info->event), &myRelativeTime);
4587
4588 triggerEvLoop();
4589 return p_info;
4590}
4591
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004592
4593extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004594RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4595 const struct timeval *relativeTime) {
4596 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004597}
4598
4599const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004600failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004601 switch(e) {
4602 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004603 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004604 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4605 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4606 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4607 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4608 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4609 case RIL_E_CANCELLED: return "E_CANCELLED";
4610 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4611 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4612 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004613 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004614 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004615#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004616 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4617 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4618#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004619 default: return "<unknown error>";
4620 }
4621}
4622
4623const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004624radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004625 switch(s) {
4626 case RADIO_STATE_OFF: return "RADIO_OFF";
4627 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4628 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4629 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4630 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004631 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4632 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4633 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4634 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4635 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004636 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004637 default: return "<unknown state>";
4638 }
4639}
4640
4641const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004642callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004643 switch(s) {
4644 case RIL_CALL_ACTIVE : return "ACTIVE";
4645 case RIL_CALL_HOLDING: return "HOLDING";
4646 case RIL_CALL_DIALING: return "DIALING";
4647 case RIL_CALL_ALERTING: return "ALERTING";
4648 case RIL_CALL_INCOMING: return "INCOMING";
4649 case RIL_CALL_WAITING: return "WAITING";
4650 default: return "<unknown state>";
4651 }
4652}
4653
4654const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004655requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004656/*
4657 cat libs/telephony/ril_commands.h \
4658 | egrep "^ *{RIL_" \
4659 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4660
4661
4662 cat libs/telephony/ril_unsol_commands.h \
4663 | egrep "^ *{RIL_" \
4664 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4665
4666*/
4667 switch(request) {
4668 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4669 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4670 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4671 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4672 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4673 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4674 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4675 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4676 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4677 case RIL_REQUEST_DIAL: return "DIAL";
4678 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4679 case RIL_REQUEST_HANGUP: return "HANGUP";
4680 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4681 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4682 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4683 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4684 case RIL_REQUEST_UDUB: return "UDUB";
4685 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4686 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004687 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4688 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004689 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4690 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4691 case RIL_REQUEST_DTMF: return "DTMF";
4692 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4693 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004694 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004695 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4696 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4697 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4698 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4699 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4700 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4701 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4702 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4703 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4704 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4705 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4706 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4707 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004708 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004709 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4710 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4711 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4712 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4713 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4714 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4715 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4716 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4717 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4718 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4719 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4720 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4721 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4722 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4723 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4724 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4725 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004726 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4727 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004728 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4729 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4730 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004731 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4732 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004733 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4734 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4735 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4736 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4737 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4738 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4739 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4740 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004741 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004742 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4743 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4744 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4745 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4746 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4747 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4748 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4749 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4750 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4751 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004752 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4753 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4754 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4755 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4756 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004757 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004758 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4759 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4760 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4761 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004762 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4763 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4764 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004765 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004766 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004767 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004768 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004769 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4770 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004771 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004772 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4773 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004774 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004775 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4776 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004777 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4778 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4779 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4780 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004781 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4782 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07004783 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4784 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004785 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4786 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004787 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4788 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004789 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004790 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4791 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004792 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 -08004793 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4794 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4795 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4796 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4797 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4798 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4799 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4800 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4801 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4802 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4803 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4804 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4805 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004806 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004807 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004808 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4809 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4810 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4811 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004812 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4813 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4814 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4815 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4816 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004817 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004818 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004819 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004820 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004821 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4822 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004823 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004824 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004825 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004826 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004827 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4828 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4829 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004830 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07004831 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004832 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004833 default: return "<unknown request>";
4834 }
4835}
4836
Etan Cohend3652192014-06-20 08:28:44 -07004837const char *
4838rilSocketIdToString(RIL_SOCKET_ID socket_id)
4839{
4840 switch(socket_id) {
4841 case RIL_SOCKET_1:
4842 return "RIL_SOCKET_1";
4843#if (SIM_COUNT >= 2)
4844 case RIL_SOCKET_2:
4845 return "RIL_SOCKET_2";
4846#endif
4847#if (SIM_COUNT >= 3)
4848 case RIL_SOCKET_3:
4849 return "RIL_SOCKET_3";
4850#endif
4851#if (SIM_COUNT >= 4)
4852 case RIL_SOCKET_4:
4853 return "RIL_SOCKET_4";
4854#endif
4855 default:
4856 return "not a valid RIL";
4857 }
4858}
4859
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004860} /* namespace android */