blob: ef93e5b8c069e22937e7f3f514fa687a99fd61c3 [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);
Amit Mahajan54563d32014-11-22 00:54:49 +0000308static int responseSSData(Parcel &p, void *response, size_t responselen);
309
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800310static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
311static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
312static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
313
Amit Mahajan54563d32014-11-22 00:54:49 +0000314static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
315
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700317#if defined(ANDROID_MULTI_SIM)
318extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
319 size_t datalen, RIL_SOCKET_ID socket_id);
320#else
Wink Saville7f856802009-06-09 10:23:37 -0700321extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800322 size_t datalen);
323#endif
Etan Cohend3652192014-06-20 08:28:44 -0700324#endif
325
326#if defined(ANDROID_MULTI_SIM)
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
330#else
331#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
332#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
333#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
334#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
Wink Saville7f856802009-06-09 10:23:37 -0700336static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700337 (RIL_TimedCallback callback, void *param,
338 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800339
340/** Index == requestNumber */
341static CommandInfo s_commands[] = {
342#include "ril_commands.h"
343};
344
345static UnsolResponseInfo s_unsolResponses[] = {
346#include "ril_unsol_commands.h"
347};
348
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800349/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
350 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
351 radio state message and store it. Every time there is a change in Radio State
352 check to see if voice radio tech changes and notify telephony
353 */
354int voiceRadioTech = -1;
355
356/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
357 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
358 source from radio state and store it. Every time there is a change in Radio State
359 check to see if subscription source changed and notify telephony
360 */
361int cdmaSubscriptionSource = -1;
362
363/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
364 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
365 check to see if SIM/RUIM status changed and notify telephony
366 */
367int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800368
Etan Cohend3652192014-06-20 08:28:44 -0700369static char * RIL_getRilSocketName() {
370 return rild;
371}
372
373extern "C"
374void RIL_setRilSocketName(char * s) {
375 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
376}
377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700379strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 size_t stringlen;
381 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700382
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800383 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700384
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800385 return strndup16to8(s16, stringlen);
386}
387
Wink Saville8b4e4f72014-10-17 15:01:45 -0700388static status_t
389readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
390 size_t s16Len;
391 const char16_t *s16;
392
393 s16 = p.readString16Inplace(&s16Len);
394 if (s16 == NULL) {
395 return NO_MEMORY;
396 }
397 size_t strLen = strnlen16to8(s16, s16Len);
398 if ((strLen + 1) > maxLen) {
399 return NO_MEMORY;
400 }
401 if (strncpy16to8(str, s16, strLen) == NULL) {
402 return NO_MEMORY;
403 } else {
404 return NO_ERROR;
405 }
406}
407
Wink Savillef4c4d362009-04-02 01:37:03 -0700408static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 char16_t *s16;
410 size_t s16_len;
411 s16 = strdup8to16(s, &s16_len);
412 p.writeString16(s16, s16_len);
413 free(s16);
414}
415
416
417static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700418memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800419 if (s != NULL) {
420 memset (s, 0, strlen(s));
421 }
422}
423
424void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
425 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700426 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 // do nothing -- the data reference lives longer than the Parcel object
428}
429
Wink Saville7f856802009-06-09 10:23:37 -0700430/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 * To be called from dispatch thread
432 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700433 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800434 */
435static void
Etan Cohend3652192014-06-20 08:28:44 -0700436issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437 RequestInfo *pRI;
438 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700439 /* Hook for current context */
440 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
441 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
442 /* pendingRequestsHook refer to &s_pendingRequests */
443 RequestInfo** pendingRequestsHook = &s_pendingRequests;
444
445#if (SIM_COUNT == 2)
446 if (socket_id == RIL_SOCKET_2) {
447 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
448 pendingRequestsHook = &s_pendingRequests_socket2;
449 }
450#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451
452 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
453
454 pRI->local = 1;
455 pRI->token = 0xffffffff; // token is not used in this context
456 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700457 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458
Etan Cohend3652192014-06-20 08:28:44 -0700459 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460 assert (ret == 0);
461
Etan Cohend3652192014-06-20 08:28:44 -0700462 pRI->p_next = *pendingRequestsHook;
463 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464
Etan Cohend3652192014-06-20 08:28:44 -0700465 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800466 assert (ret == 0);
467
Wink Saville8eb2a122012-11-19 16:05:13 -0800468 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800469
Etan Cohend3652192014-06-20 08:28:44 -0700470 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471}
472
473
474
475static int
Etan Cohend3652192014-06-20 08:28:44 -0700476processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800477 Parcel p;
478 status_t status;
479 int32_t request;
480 int32_t token;
481 RequestInfo *pRI;
482 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700483 /* Hook for current context */
484 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
485 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
486 /* pendingRequestsHook refer to &s_pendingRequests */
487 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800488
489 p.setData((uint8_t *) buffer, buflen);
490
491 // status checked at end
492 status = p.readInt32(&request);
493 status = p.readInt32 (&token);
494
Etan Cohend3652192014-06-20 08:28:44 -0700495 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
496
497#if (SIM_COUNT >= 2)
498 if (socket_id == RIL_SOCKET_2) {
499 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
500 pendingRequestsHook = &s_pendingRequests_socket2;
501 }
502#if (SIM_COUNT >= 3)
503 else if (socket_id == RIL_SOCKET_3) {
504 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
505 pendingRequestsHook = &s_pendingRequests_socket3;
506 }
507#endif
508#if (SIM_COUNT >= 4)
509 else if (socket_id == RIL_SOCKET_4) {
510 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
511 pendingRequestsHook = &s_pendingRequests_socket4;
512 }
513#endif
514#endif
515
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800517 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800518 return 0;
519 }
520
521 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700522 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800523 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800524 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700525 pErr.writeInt32 (RESPONSE_SOLICITED);
526 pErr.writeInt32 (token);
527 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
528
529 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800530 return 0;
531 }
532
533
534 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
535
536 pRI->token = token;
537 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700538 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539
Etan Cohend3652192014-06-20 08:28:44 -0700540 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541 assert (ret == 0);
542
Etan Cohend3652192014-06-20 08:28:44 -0700543 pRI->p_next = *pendingRequestsHook;
544 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545
Etan Cohend3652192014-06-20 08:28:44 -0700546 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547 assert (ret == 0);
548
549/* sLastDispatchedToken = token; */
550
Wink Saville7f856802009-06-09 10:23:37 -0700551 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552
553 return 0;
554}
555
556static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700557invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800558 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559 pRI->token, requestToString(pRI->pCI->requestNumber));
560}
561
562/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700563static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700564dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800565 clearPrintBuf;
566 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700567 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800568}
569
570/** Callee expects const char * */
571static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700572dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800573 status_t status;
574 size_t datalen;
575 size_t stringlen;
576 char *string8 = NULL;
577
578 string8 = strdupReadString(p);
579
580 startRequest;
581 appendPrintBuf("%s%s", printBuf, string8);
582 closeRequest;
583 printRequest(pRI->token, pRI->pCI->requestNumber);
584
Etan Cohend3652192014-06-20 08:28:44 -0700585 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
586 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800587
588#ifdef MEMSET_FREED
589 memsetString(string8);
590#endif
591
592 free(string8);
593 return;
594invalid:
595 invalidCommandBlock(pRI);
596 return;
597}
598
599/** Callee expects const char ** */
600static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700601dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800602 int32_t countStrings;
603 status_t status;
604 size_t datalen;
605 char **pStrings;
606
607 status = p.readInt32 (&countStrings);
608
609 if (status != NO_ERROR) {
610 goto invalid;
611 }
612
613 startRequest;
614 if (countStrings == 0) {
615 // just some non-null pointer
616 pStrings = (char **)alloca(sizeof(char *));
617 datalen = 0;
618 } else if (((int)countStrings) == -1) {
619 pStrings = NULL;
620 datalen = 0;
621 } else {
622 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700623
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800624 pStrings = (char **)alloca(datalen);
625
626 for (int i = 0 ; i < countStrings ; i++) {
627 pStrings[i] = strdupReadString(p);
628 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
629 }
630 }
631 removeLastChar;
632 closeRequest;
633 printRequest(pRI->token, pRI->pCI->requestNumber);
634
Etan Cohend3652192014-06-20 08:28:44 -0700635 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800636
637 if (pStrings != NULL) {
638 for (int i = 0 ; i < countStrings ; i++) {
639#ifdef MEMSET_FREED
640 memsetString (pStrings[i]);
641#endif
642 free(pStrings[i]);
643 }
644
645#ifdef MEMSET_FREED
646 memset(pStrings, 0, datalen);
647#endif
648 }
Wink Saville7f856802009-06-09 10:23:37 -0700649
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800650 return;
651invalid:
652 invalidCommandBlock(pRI);
653 return;
654}
655
656/** Callee expects const int * */
657static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700658dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800659 int32_t count;
660 status_t status;
661 size_t datalen;
662 int *pInts;
663
664 status = p.readInt32 (&count);
665
666 if (status != NO_ERROR || count == 0) {
667 goto invalid;
668 }
669
670 datalen = sizeof(int) * count;
671 pInts = (int *)alloca(datalen);
672
673 startRequest;
674 for (int i = 0 ; i < count ; i++) {
675 int32_t t;
676
677 status = p.readInt32(&t);
678 pInts[i] = (int)t;
679 appendPrintBuf("%s%d,", printBuf, t);
680
681 if (status != NO_ERROR) {
682 goto invalid;
683 }
684 }
685 removeLastChar;
686 closeRequest;
687 printRequest(pRI->token, pRI->pCI->requestNumber);
688
Etan Cohend3652192014-06-20 08:28:44 -0700689 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
690 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800691
692#ifdef MEMSET_FREED
693 memset(pInts, 0, datalen);
694#endif
695
696 return;
697invalid:
698 invalidCommandBlock(pRI);
699 return;
700}
701
702
Wink Saville7f856802009-06-09 10:23:37 -0700703/**
704 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800705 * Payload is:
706 * int32_t status
707 * String pdu
708 */
709static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700710dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800711 RIL_SMS_WriteArgs args;
712 int32_t t;
713 status_t status;
714
715 memset (&args, 0, sizeof(args));
716
717 status = p.readInt32(&t);
718 args.status = (int)t;
719
720 args.pdu = strdupReadString(p);
721
722 if (status != NO_ERROR || args.pdu == NULL) {
723 goto invalid;
724 }
725
726 args.smsc = strdupReadString(p);
727
728 startRequest;
729 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
730 (char*)args.pdu, (char*)args.smsc);
731 closeRequest;
732 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700733
Etan Cohend3652192014-06-20 08:28:44 -0700734 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800735
736#ifdef MEMSET_FREED
737 memsetString (args.pdu);
738#endif
739
740 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700741
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800742#ifdef MEMSET_FREED
743 memset(&args, 0, sizeof(args));
744#endif
745
746 return;
747invalid:
748 invalidCommandBlock(pRI);
749 return;
750}
751
Wink Saville7f856802009-06-09 10:23:37 -0700752/**
753 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754 * Payload is:
755 * String address
756 * int32_t clir
757 */
758static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700759dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800760 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800761 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800762 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800763 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800764 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800765 status_t status;
766
767 memset (&dial, 0, sizeof(dial));
768
769 dial.address = strdupReadString(p);
770
771 status = p.readInt32(&t);
772 dial.clir = (int)t;
773
774 if (status != NO_ERROR || dial.address == NULL) {
775 goto invalid;
776 }
777
Wink Saville3a4840b2010-04-07 13:29:58 -0700778 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800779 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800780 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800781 } else {
782 status = p.readInt32(&uusPresent);
783
784 if (status != NO_ERROR) {
785 goto invalid;
786 }
787
788 if (uusPresent == 0) {
789 dial.uusInfo = NULL;
790 } else {
791 int32_t len;
792
793 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
794
795 status = p.readInt32(&t);
796 uusInfo.uusType = (RIL_UUS_Type) t;
797
798 status = p.readInt32(&t);
799 uusInfo.uusDcs = (RIL_UUS_DCS) t;
800
801 status = p.readInt32(&len);
802 if (status != NO_ERROR) {
803 goto invalid;
804 }
805
806 // The java code writes -1 for null arrays
807 if (((int) len) == -1) {
808 uusInfo.uusData = NULL;
809 len = 0;
810 } else {
811 uusInfo.uusData = (char*) p.readInplace(len);
812 }
813
814 uusInfo.uusLength = len;
815 dial.uusInfo = &uusInfo;
816 }
Wink Saville7bce0822010-01-08 15:20:12 -0800817 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800818 }
819
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800820 startRequest;
821 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800822 if (uusPresent) {
823 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
824 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
825 dial.uusInfo->uusLength);
826 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800827 closeRequest;
828 printRequest(pRI->token, pRI->pCI->requestNumber);
829
Etan Cohend3652192014-06-20 08:28:44 -0700830 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800831
832#ifdef MEMSET_FREED
833 memsetString (dial.address);
834#endif
835
836 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700837
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800839 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800840 memset(&dial, 0, sizeof(dial));
841#endif
842
843 return;
844invalid:
845 invalidCommandBlock(pRI);
846 return;
847}
848
Wink Saville7f856802009-06-09 10:23:37 -0700849/**
850 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800851 * Payload is:
852 * int32_t command
853 * int32_t fileid
854 * String path
855 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700856 * String data
857 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800858 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859 */
860static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700861dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800862 union RIL_SIM_IO {
863 RIL_SIM_IO_v6 v6;
864 RIL_SIM_IO_v5 v5;
865 } simIO;
866
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800868 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869 status_t status;
870
871 memset (&simIO, 0, sizeof(simIO));
872
Wink Saville7f856802009-06-09 10:23:37 -0700873 // note we only check status at the end
874
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800875 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800876 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877
878 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800879 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880
Wink Savillec0114b32011-02-18 10:14:07 -0800881 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800882
883 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800884 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885
886 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800887 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888
889 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800890 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891
Wink Savillec0114b32011-02-18 10:14:07 -0800892 simIO.v6.data = strdupReadString(p);
893 simIO.v6.pin2 = strdupReadString(p);
894 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800895
896 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800897 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
898 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
899 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
900 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800901 closeRequest;
902 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700903
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800904 if (status != NO_ERROR) {
905 goto invalid;
906 }
907
Wink Savillec0114b32011-02-18 10:14:07 -0800908 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700909 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800910
911#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800912 memsetString (simIO.v6.path);
913 memsetString (simIO.v6.data);
914 memsetString (simIO.v6.pin2);
915 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800916#endif
917
Wink Savillec0114b32011-02-18 10:14:07 -0800918 free (simIO.v6.path);
919 free (simIO.v6.data);
920 free (simIO.v6.pin2);
921 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700922
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800923#ifdef MEMSET_FREED
924 memset(&simIO, 0, sizeof(simIO));
925#endif
926
927 return;
928invalid:
929 invalidCommandBlock(pRI);
930 return;
931}
932
933/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800934 * Callee expects const RIL_SIM_APDU *
935 * Payload is:
936 * int32_t sessionid
937 * int32_t cla
938 * int32_t instruction
939 * int32_t p1, p2, p3
940 * String data
941 */
942static void
943dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
944 int32_t t;
945 status_t status;
946 RIL_SIM_APDU apdu;
947
948 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
949
950 // Note we only check status at the end. Any single failure leads to
951 // subsequent reads filing.
952 status = p.readInt32(&t);
953 apdu.sessionid = (int)t;
954
955 status = p.readInt32(&t);
956 apdu.cla = (int)t;
957
958 status = p.readInt32(&t);
959 apdu.instruction = (int)t;
960
961 status = p.readInt32(&t);
962 apdu.p1 = (int)t;
963
964 status = p.readInt32(&t);
965 apdu.p2 = (int)t;
966
967 status = p.readInt32(&t);
968 apdu.p3 = (int)t;
969
970 apdu.data = strdupReadString(p);
971
972 startRequest;
973 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
974 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
975 apdu.p3, (char*)apdu.data);
976 closeRequest;
977 printRequest(pRI->token, pRI->pCI->requestNumber);
978
979 if (status != NO_ERROR) {
980 goto invalid;
981 }
982
Etan Cohend3652192014-06-20 08:28:44 -0700983 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800984
985#ifdef MEMSET_FREED
986 memsetString(apdu.data);
987#endif
988 free(apdu.data);
989
990#ifdef MEMSET_FREED
991 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
992#endif
993
994 return;
995invalid:
996 invalidCommandBlock(pRI);
997 return;
998}
999
1000
1001/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001002 * Callee expects const RIL_CallForwardInfo *
1003 * Payload is:
1004 * int32_t status/action
1005 * int32_t reason
1006 * int32_t serviceCode
1007 * int32_t toa
1008 * String number (0 length -> null)
1009 * int32_t timeSeconds
1010 */
Wink Saville7f856802009-06-09 10:23:37 -07001011static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001012dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001013 RIL_CallForwardInfo cff;
1014 int32_t t;
1015 status_t status;
1016
1017 memset (&cff, 0, sizeof(cff));
1018
Wink Saville7f856802009-06-09 10:23:37 -07001019 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001020
1021 status = p.readInt32(&t);
1022 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001023
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001024 status = p.readInt32(&t);
1025 cff.reason = (int)t;
1026
1027 status = p.readInt32(&t);
1028 cff.serviceClass = (int)t;
1029
1030 status = p.readInt32(&t);
1031 cff.toa = (int)t;
1032
1033 cff.number = strdupReadString(p);
1034
1035 status = p.readInt32(&t);
1036 cff.timeSeconds = (int)t;
1037
1038 if (status != NO_ERROR) {
1039 goto invalid;
1040 }
1041
1042 // special case: number 0-length fields is null
1043
1044 if (cff.number != NULL && strlen (cff.number) == 0) {
1045 cff.number = NULL;
1046 }
1047
1048 startRequest;
1049 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1050 cff.status, cff.reason, cff.serviceClass, cff.toa,
1051 (char*)cff.number, cff.timeSeconds);
1052 closeRequest;
1053 printRequest(pRI->token, pRI->pCI->requestNumber);
1054
Etan Cohend3652192014-06-20 08:28:44 -07001055 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001056
1057#ifdef MEMSET_FREED
1058 memsetString(cff.number);
1059#endif
1060
1061 free (cff.number);
1062
1063#ifdef MEMSET_FREED
1064 memset(&cff, 0, sizeof(cff));
1065#endif
1066
1067 return;
1068invalid:
1069 invalidCommandBlock(pRI);
1070 return;
1071}
1072
1073
Wink Saville7f856802009-06-09 10:23:37 -07001074static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001075dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001076 int32_t len;
1077 status_t status;
1078 const void *data;
1079
1080 status = p.readInt32(&len);
1081
1082 if (status != NO_ERROR) {
1083 goto invalid;
1084 }
1085
1086 // The java code writes -1 for null arrays
1087 if (((int)len) == -1) {
1088 data = NULL;
1089 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001090 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001091
1092 data = p.readInplace(len);
1093
1094 startRequest;
1095 appendPrintBuf("%sraw_size=%d", printBuf, len);
1096 closeRequest;
1097 printRequest(pRI->token, pRI->pCI->requestNumber);
1098
Etan Cohend3652192014-06-20 08:28:44 -07001099 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001100
1101 return;
1102invalid:
1103 invalidCommandBlock(pRI);
1104 return;
1105}
1106
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001107static status_t
1108constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001109 int32_t t;
1110 uint8_t ut;
1111 status_t status;
1112 int32_t digitCount;
1113 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001114
Wink Savillef4c4d362009-04-02 01:37:03 -07001115 memset(&rcsm, 0, sizeof(rcsm));
1116
1117 status = p.readInt32(&t);
1118 rcsm.uTeleserviceID = (int) t;
1119
1120 status = p.read(&ut,sizeof(ut));
1121 rcsm.bIsServicePresent = (uint8_t) ut;
1122
1123 status = p.readInt32(&t);
1124 rcsm.uServicecategory = (int) t;
1125
1126 status = p.readInt32(&t);
1127 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1128
1129 status = p.readInt32(&t);
1130 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1131
1132 status = p.readInt32(&t);
1133 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1134
1135 status = p.readInt32(&t);
1136 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1137
1138 status = p.read(&ut,sizeof(ut));
1139 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1140
1141 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1142 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1143 status = p.read(&ut,sizeof(ut));
1144 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1145 }
1146
Wink Saville7f856802009-06-09 10:23:37 -07001147 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001148 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1149
Wink Saville7f856802009-06-09 10:23:37 -07001150 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001151 rcsm.sSubAddress.odd = (uint8_t) ut;
1152
1153 status = p.read(&ut,sizeof(ut));
1154 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1155
1156 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001157 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1158 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1160 }
1161
Wink Saville7f856802009-06-09 10:23:37 -07001162 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001163 rcsm.uBearerDataLen = (int) t;
1164
1165 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001166 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1167 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001168 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1169 }
1170
1171 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001172 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001173 }
1174
1175 startRequest;
1176 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001177 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001179 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001180 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001181
Wink Savillef4c4d362009-04-02 01:37:03 -07001182 printRequest(pRI->token, pRI->pCI->requestNumber);
1183
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001184 return status;
1185}
1186
1187static void
1188dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1189 RIL_CDMA_SMS_Message rcsm;
1190
1191 ALOGD("dispatchCdmaSms");
1192 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1193 goto invalid;
1194 }
1195
Etan Cohend3652192014-06-20 08:28:44 -07001196 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001197
1198#ifdef MEMSET_FREED
1199 memset(&rcsm, 0, sizeof(rcsm));
1200#endif
1201
1202 return;
1203
1204invalid:
1205 invalidCommandBlock(pRI);
1206 return;
1207}
1208
Wink Saville7f856802009-06-09 10:23:37 -07001209static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001210dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1211 RIL_IMS_SMS_Message rism;
1212 RIL_CDMA_SMS_Message rcsm;
1213
1214 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1215
1216 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1217 goto invalid;
1218 }
1219 memset(&rism, 0, sizeof(rism));
1220 rism.tech = RADIO_TECH_3GPP2;
1221 rism.retry = retry;
1222 rism.messageRef = messageRef;
1223 rism.message.cdmaMessage = &rcsm;
1224
Etan Cohend3652192014-06-20 08:28:44 -07001225 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001226 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001227 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001228
1229#ifdef MEMSET_FREED
1230 memset(&rcsm, 0, sizeof(rcsm));
1231 memset(&rism, 0, sizeof(rism));
1232#endif
1233
1234 return;
1235
1236invalid:
1237 invalidCommandBlock(pRI);
1238 return;
1239}
1240
1241static void
1242dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1243 RIL_IMS_SMS_Message rism;
1244 int32_t countStrings;
1245 status_t status;
1246 size_t datalen;
1247 char **pStrings;
1248 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1249
1250 status = p.readInt32 (&countStrings);
1251
1252 if (status != NO_ERROR) {
1253 goto invalid;
1254 }
1255
1256 memset(&rism, 0, sizeof(rism));
1257 rism.tech = RADIO_TECH_3GPP;
1258 rism.retry = retry;
1259 rism.messageRef = messageRef;
1260
1261 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001262 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1263 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001264 if (countStrings == 0) {
1265 // just some non-null pointer
1266 pStrings = (char **)alloca(sizeof(char *));
1267 datalen = 0;
1268 } else if (((int)countStrings) == -1) {
1269 pStrings = NULL;
1270 datalen = 0;
1271 } else {
1272 datalen = sizeof(char *) * countStrings;
1273
1274 pStrings = (char **)alloca(datalen);
1275
1276 for (int i = 0 ; i < countStrings ; i++) {
1277 pStrings[i] = strdupReadString(p);
1278 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1279 }
1280 }
1281 removeLastChar;
1282 closeRequest;
1283 printRequest(pRI->token, pRI->pCI->requestNumber);
1284
1285 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001286 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001287 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001288 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001289
1290 if (pStrings != NULL) {
1291 for (int i = 0 ; i < countStrings ; i++) {
1292#ifdef MEMSET_FREED
1293 memsetString (pStrings[i]);
1294#endif
1295 free(pStrings[i]);
1296 }
1297
1298#ifdef MEMSET_FREED
1299 memset(pStrings, 0, datalen);
1300#endif
1301 }
1302
1303#ifdef MEMSET_FREED
1304 memset(&rism, 0, sizeof(rism));
1305#endif
1306 return;
1307invalid:
1308 ALOGE("dispatchImsGsmSms invalid block");
1309 invalidCommandBlock(pRI);
1310 return;
1311}
1312
1313static void
1314dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1315 int32_t t;
1316 status_t status = p.readInt32(&t);
1317 RIL_RadioTechnologyFamily format;
1318 uint8_t retry;
1319 int32_t messageRef;
1320
1321 ALOGD("dispatchImsSms");
1322 if (status != NO_ERROR) {
1323 goto invalid;
1324 }
1325 format = (RIL_RadioTechnologyFamily) t;
1326
1327 // read retry field
1328 status = p.read(&retry,sizeof(retry));
1329 if (status != NO_ERROR) {
1330 goto invalid;
1331 }
1332 // read messageRef field
1333 status = p.read(&messageRef,sizeof(messageRef));
1334 if (status != NO_ERROR) {
1335 goto invalid;
1336 }
1337
1338 if (RADIO_TECH_3GPP == format) {
1339 dispatchImsGsmSms(p, pRI, retry, messageRef);
1340 } else if (RADIO_TECH_3GPP2 == format) {
1341 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1342 } else {
1343 ALOGE("requestImsSendSMS invalid format value =%d", format);
1344 }
1345
1346 return;
1347
1348invalid:
1349 invalidCommandBlock(pRI);
1350 return;
1351}
1352
1353static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001354dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1355 RIL_CDMA_SMS_Ack rcsa;
1356 int32_t t;
1357 status_t status;
1358 int32_t digitCount;
1359
1360 memset(&rcsa, 0, sizeof(rcsa));
1361
1362 status = p.readInt32(&t);
1363 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1364
1365 status = p.readInt32(&t);
1366 rcsa.uSMSCauseCode = (int) t;
1367
1368 if (status != NO_ERROR) {
1369 goto invalid;
1370 }
1371
1372 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001373 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1374 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001375 closeRequest;
1376
1377 printRequest(pRI->token, pRI->pCI->requestNumber);
1378
Etan Cohend3652192014-06-20 08:28:44 -07001379 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001380
1381#ifdef MEMSET_FREED
1382 memset(&rcsa, 0, sizeof(rcsa));
1383#endif
1384
1385 return;
1386
1387invalid:
1388 invalidCommandBlock(pRI);
1389 return;
1390}
1391
Wink Savillea592eeb2009-05-22 13:26:36 -07001392static void
1393dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1394 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001395 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001396 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001397
Wink Savillea592eeb2009-05-22 13:26:36 -07001398 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001399 if (status != NO_ERROR) {
1400 goto invalid;
1401 }
1402
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001403 {
1404 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1405 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001406
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001407 startRequest;
1408 for (int i = 0 ; i < num ; i++ ) {
1409 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001410
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001411 status = p.readInt32(&t);
1412 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001413
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001414 status = p.readInt32(&t);
1415 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001416
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001417 status = p.readInt32(&t);
1418 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001419
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 status = p.readInt32(&t);
1421 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001422
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001423 status = p.readInt32(&t);
1424 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001425
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001426 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1427 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1428 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1429 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1430 gsmBci[i].selected);
1431 }
1432 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001433
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001434 if (status != NO_ERROR) {
1435 goto invalid;
1436 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001437
Etan Cohend3652192014-06-20 08:28:44 -07001438 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001439 gsmBciPtrs,
1440 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001441 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001442
1443#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001444 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1445 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001446#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001447 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001448
1449 return;
1450
1451invalid:
1452 invalidCommandBlock(pRI);
1453 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001454}
Wink Savillef4c4d362009-04-02 01:37:03 -07001455
Wink Savillea592eeb2009-05-22 13:26:36 -07001456static void
1457dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1458 int32_t t;
1459 status_t status;
1460 int32_t num;
1461
1462 status = p.readInt32(&num);
1463 if (status != NO_ERROR) {
1464 goto invalid;
1465 }
1466
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 {
1468 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1469 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001470
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001471 startRequest;
1472 for (int i = 0 ; i < num ; i++ ) {
1473 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001474
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 status = p.readInt32(&t);
1476 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 status = p.readInt32(&t);
1479 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001480
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 status = p.readInt32(&t);
1482 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001483
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1485 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1486 cdmaBci[i].language, cdmaBci[i].selected);
1487 }
1488 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001489
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001490 if (status != NO_ERROR) {
1491 goto invalid;
1492 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001493
Etan Cohend3652192014-06-20 08:28:44 -07001494 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001495 cdmaBciPtrs,
1496 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001497 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
1499#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001500 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1501 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001502#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001503 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001504
1505 return;
1506
1507invalid:
1508 invalidCommandBlock(pRI);
1509 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001510}
1511
1512static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1513 RIL_CDMA_SMS_WriteArgs rcsw;
1514 int32_t t;
1515 uint32_t ut;
1516 uint8_t uct;
1517 status_t status;
1518 int32_t digitCount;
1519
1520 memset(&rcsw, 0, sizeof(rcsw));
1521
1522 status = p.readInt32(&t);
1523 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001524
Wink Savillef4c4d362009-04-02 01:37:03 -07001525 status = p.readInt32(&t);
1526 rcsw.message.uTeleserviceID = (int) t;
1527
1528 status = p.read(&uct,sizeof(uct));
1529 rcsw.message.bIsServicePresent = (uint8_t) uct;
1530
1531 status = p.readInt32(&t);
1532 rcsw.message.uServicecategory = (int) t;
1533
1534 status = p.readInt32(&t);
1535 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1536
1537 status = p.readInt32(&t);
1538 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1539
1540 status = p.readInt32(&t);
1541 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1542
1543 status = p.readInt32(&t);
1544 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1545
1546 status = p.read(&uct,sizeof(uct));
1547 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1548
1549 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1550 status = p.read(&uct,sizeof(uct));
1551 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1552 }
1553
Wink Savillea592eeb2009-05-22 13:26:36 -07001554 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001555 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1556
Wink Savillea592eeb2009-05-22 13:26:36 -07001557 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001558 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1559
1560 status = p.read(&uct,sizeof(uct));
1561 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1562
1563 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001564 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001565 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1566 }
1567
Wink Savillea592eeb2009-05-22 13:26:36 -07001568 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001569 rcsw.message.uBearerDataLen = (int) t;
1570
1571 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001572 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001573 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1574 }
1575
1576 if (status != NO_ERROR) {
1577 goto invalid;
1578 }
1579
1580 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001581 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1582 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1583 message.sAddress.number_mode=%d, \
1584 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001586 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1587 rcsw.message.sAddress.number_mode,
1588 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001589 closeRequest;
1590
1591 printRequest(pRI->token, pRI->pCI->requestNumber);
1592
Etan Cohend3652192014-06-20 08:28:44 -07001593 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001594
1595#ifdef MEMSET_FREED
1596 memset(&rcsw, 0, sizeof(rcsw));
1597#endif
1598
1599 return;
1600
1601invalid:
1602 invalidCommandBlock(pRI);
1603 return;
1604
1605}
1606
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001607// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1608// Version 4 of the RIL interface adds a new PDP type parameter to support
1609// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1610// RIL, remove the parameter from the request.
1611static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1612 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1613 const int numParamsRilV3 = 6;
1614
1615 // The first bytes of the RIL parcel contain the request number and the
1616 // serial number - see processCommandBuffer(). Copy them over too.
1617 int pos = p.dataPosition();
1618
1619 int numParams = p.readInt32();
1620 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1621 Parcel p2;
1622 p2.appendFrom(&p, 0, pos);
1623 p2.writeInt32(numParamsRilV3);
1624 for(int i = 0; i < numParamsRilV3; i++) {
1625 p2.writeString16(p.readString16());
1626 }
1627 p2.setDataPosition(pos);
1628 dispatchStrings(p2, pRI);
1629 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001630 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001631 dispatchStrings(p, pRI);
1632 }
1633}
1634
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001635// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1636// When all RILs handle this request, this function can be removed and
1637// the request can be sent directly to the RIL using dispatchVoid.
1638static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001639 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001640
1641 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1642 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1643 }
1644
1645 // RILs that support RADIO_STATE_ON should support this request.
1646 if (RADIO_STATE_ON == state) {
1647 dispatchVoid(p, pRI);
1648 return;
1649 }
1650
1651 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1652 // will not support this new request either and decode Voice Radio Technology
1653 // from Radio State
1654 voiceRadioTech = decodeVoiceRadioTechnology(state);
1655
1656 if (voiceRadioTech < 0)
1657 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1658 else
1659 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1660}
1661
1662// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1663// When all RILs handle this request, this function can be removed and
1664// the request can be sent directly to the RIL using dispatchVoid.
1665static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001666 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001667
1668 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1669 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1670 }
1671
1672 // RILs that support RADIO_STATE_ON should support this request.
1673 if (RADIO_STATE_ON == state) {
1674 dispatchVoid(p, pRI);
1675 return;
1676 }
1677
1678 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1679 // will not support this new request either and decode CDMA Subscription Source
1680 // from Radio State
1681 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1682
1683 if (cdmaSubscriptionSource < 0)
1684 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1685 else
1686 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1687}
1688
Sungmin Choi75697532013-04-26 15:04:45 -07001689static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1690{
1691 RIL_InitialAttachApn pf;
1692 int32_t t;
1693 status_t status;
1694
1695 memset(&pf, 0, sizeof(pf));
1696
1697 pf.apn = strdupReadString(p);
1698 pf.protocol = strdupReadString(p);
1699
1700 status = p.readInt32(&t);
1701 pf.authtype = (int) t;
1702
1703 pf.username = strdupReadString(p);
1704 pf.password = strdupReadString(p);
1705
1706 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001707 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1708 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001709 closeRequest;
1710 printRequest(pRI->token, pRI->pCI->requestNumber);
1711
1712 if (status != NO_ERROR) {
1713 goto invalid;
1714 }
Etan Cohend3652192014-06-20 08:28:44 -07001715 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001716
1717#ifdef MEMSET_FREED
1718 memsetString(pf.apn);
1719 memsetString(pf.protocol);
1720 memsetString(pf.username);
1721 memsetString(pf.password);
1722#endif
1723
1724 free(pf.apn);
1725 free(pf.protocol);
1726 free(pf.username);
1727 free(pf.password);
1728
1729#ifdef MEMSET_FREED
1730 memset(&pf, 0, sizeof(pf));
1731#endif
1732
1733 return;
1734invalid:
1735 invalidCommandBlock(pRI);
1736 return;
1737}
1738
Jake Hamby8a4a2332014-01-15 13:12:05 -08001739static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1740 RIL_NV_ReadItem nvri;
1741 int32_t t;
1742 status_t status;
1743
1744 memset(&nvri, 0, sizeof(nvri));
1745
1746 status = p.readInt32(&t);
1747 nvri.itemID = (RIL_NV_Item) t;
1748
1749 if (status != NO_ERROR) {
1750 goto invalid;
1751 }
1752
1753 startRequest;
1754 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1755 closeRequest;
1756
1757 printRequest(pRI->token, pRI->pCI->requestNumber);
1758
Etan Cohend3652192014-06-20 08:28:44 -07001759 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001760
1761#ifdef MEMSET_FREED
1762 memset(&nvri, 0, sizeof(nvri));
1763#endif
1764
1765 return;
1766
1767invalid:
1768 invalidCommandBlock(pRI);
1769 return;
1770}
1771
1772static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1773 RIL_NV_WriteItem nvwi;
1774 int32_t t;
1775 status_t status;
1776
1777 memset(&nvwi, 0, sizeof(nvwi));
1778
1779 status = p.readInt32(&t);
1780 nvwi.itemID = (RIL_NV_Item) t;
1781
1782 nvwi.value = strdupReadString(p);
1783
1784 if (status != NO_ERROR || nvwi.value == NULL) {
1785 goto invalid;
1786 }
1787
1788 startRequest;
1789 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1790 nvwi.value);
1791 closeRequest;
1792
1793 printRequest(pRI->token, pRI->pCI->requestNumber);
1794
Etan Cohend3652192014-06-20 08:28:44 -07001795 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001796
1797#ifdef MEMSET_FREED
1798 memsetString(nvwi.value);
1799#endif
1800
1801 free(nvwi.value);
1802
1803#ifdef MEMSET_FREED
1804 memset(&nvwi, 0, sizeof(nvwi));
1805#endif
1806
1807 return;
1808
1809invalid:
1810 invalidCommandBlock(pRI);
1811 return;
1812}
1813
1814
Etan Cohend3652192014-06-20 08:28:44 -07001815static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1816 RIL_SelectUiccSub uicc_sub;
1817 status_t status;
1818 int32_t t;
1819 memset(&uicc_sub, 0, sizeof(uicc_sub));
1820
1821 status = p.readInt32(&t);
1822 if (status != NO_ERROR) {
1823 goto invalid;
1824 }
1825 uicc_sub.slot = (int) t;
1826
1827 status = p.readInt32(&t);
1828 if (status != NO_ERROR) {
1829 goto invalid;
1830 }
1831 uicc_sub.app_index = (int) t;
1832
1833 status = p.readInt32(&t);
1834 if (status != NO_ERROR) {
1835 goto invalid;
1836 }
1837 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1838
1839 status = p.readInt32(&t);
1840 if (status != NO_ERROR) {
1841 goto invalid;
1842 }
1843 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1844
1845 startRequest;
1846 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1847 uicc_sub.act_status);
1848 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1849 uicc_sub.app_index, uicc_sub.act_status);
1850 closeRequest;
1851 printRequest(pRI->token, pRI->pCI->requestNumber);
1852
1853 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1854
1855#ifdef MEMSET_FREED
1856 memset(&uicc_sub, 0, sizeof(uicc_sub));
1857#endif
1858 return;
1859
1860invalid:
1861 invalidCommandBlock(pRI);
1862 return;
1863}
1864
Amit Mahajan90530a62014-07-01 15:54:08 -07001865static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1866{
1867 RIL_SimAuthentication pf;
1868 int32_t t;
1869 status_t status;
1870
1871 memset(&pf, 0, sizeof(pf));
1872
1873 status = p.readInt32(&t);
1874 pf.authContext = (int) t;
1875 pf.authData = strdupReadString(p);
1876 pf.aid = strdupReadString(p);
1877
1878 startRequest;
1879 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1880 closeRequest;
1881 printRequest(pRI->token, pRI->pCI->requestNumber);
1882
1883 if (status != NO_ERROR) {
1884 goto invalid;
1885 }
1886 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1887
1888#ifdef MEMSET_FREED
1889 memsetString(pf.authData);
1890 memsetString(pf.aid);
1891#endif
1892
1893 free(pf.authData);
1894 free(pf.aid);
1895
1896#ifdef MEMSET_FREED
1897 memset(&pf, 0, sizeof(pf));
1898#endif
1899
1900 return;
1901invalid:
1902 invalidCommandBlock(pRI);
1903 return;
1904}
1905
Amit Mahajanc796e222014-08-13 16:54:01 +00001906static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1907 int32_t t;
1908 status_t status;
1909 int32_t num;
1910
1911 status = p.readInt32(&num);
1912 if (status != NO_ERROR) {
1913 goto invalid;
1914 }
1915
1916 {
1917 RIL_DataProfileInfo dataProfiles[num];
1918 RIL_DataProfileInfo *dataProfilePtrs[num];
1919
1920 startRequest;
1921 for (int i = 0 ; i < num ; i++ ) {
1922 dataProfilePtrs[i] = &dataProfiles[i];
1923
1924 status = p.readInt32(&t);
1925 dataProfiles[i].profileId = (int) t;
1926
1927 dataProfiles[i].apn = strdupReadString(p);
1928 dataProfiles[i].protocol = strdupReadString(p);
1929 status = p.readInt32(&t);
1930 dataProfiles[i].authType = (int) t;
1931
1932 dataProfiles[i].user = strdupReadString(p);
1933 dataProfiles[i].password = strdupReadString(p);
1934
1935 status = p.readInt32(&t);
1936 dataProfiles[i].type = (int) t;
1937
1938 status = p.readInt32(&t);
1939 dataProfiles[i].maxConnsTime = (int) t;
1940 status = p.readInt32(&t);
1941 dataProfiles[i].maxConns = (int) t;
1942 status = p.readInt32(&t);
1943 dataProfiles[i].waitTime = (int) t;
1944
1945 status = p.readInt32(&t);
1946 dataProfiles[i].enabled = (int) t;
1947
1948 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1949 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1950 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1951 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1952 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1953 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1954 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1955 }
1956 closeRequest;
1957 printRequest(pRI->token, pRI->pCI->requestNumber);
1958
1959 if (status != NO_ERROR) {
1960 goto invalid;
1961 }
1962 CALL_ONREQUEST(pRI->pCI->requestNumber,
1963 dataProfilePtrs,
1964 num * sizeof(RIL_DataProfileInfo *),
1965 pRI, pRI->socket_id);
1966
1967#ifdef MEMSET_FREED
1968 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1969 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1970#endif
1971 }
1972
1973 return;
1974
1975invalid:
1976 invalidCommandBlock(pRI);
1977 return;
1978}
1979
Wink Saville8b4e4f72014-10-17 15:01:45 -07001980static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1981 RIL_RadioCapability rc;
1982 int32_t t;
1983 status_t status;
1984
1985 memset (&rc, 0, sizeof(RIL_RadioCapability));
1986
1987 status = p.readInt32(&t);
1988 rc.version = (int)t;
1989 if (status != NO_ERROR) {
1990 goto invalid;
1991 }
1992
1993 status = p.readInt32(&t);
1994 rc.session= (int)t;
1995 if (status != NO_ERROR) {
1996 goto invalid;
1997 }
1998
1999 status = p.readInt32(&t);
2000 rc.phase= (int)t;
2001 if (status != NO_ERROR) {
2002 goto invalid;
2003 }
2004
2005 status = p.readInt32(&t);
2006 rc.rat = (int)t;
2007 if (status != NO_ERROR) {
2008 goto invalid;
2009 }
2010
2011 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2012 if (status != NO_ERROR) {
2013 goto invalid;
2014 }
2015
2016 status = p.readInt32(&t);
2017 rc.status = (int)t;
2018
2019 if (status != NO_ERROR) {
2020 goto invalid;
2021 }
2022
2023 startRequest;
2024 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002025 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2026 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002027
2028 closeRequest;
2029 printRequest(pRI->token, pRI->pCI->requestNumber);
2030
2031 CALL_ONREQUEST(pRI->pCI->requestNumber,
2032 &rc,
2033 sizeof(RIL_RadioCapability),
2034 pRI, pRI->socket_id);
2035 return;
2036invalid:
2037 invalidCommandBlock(pRI);
2038 return;
2039}
2040
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002041static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002042blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002043 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002044 const uint8_t *toWrite;
2045
2046 toWrite = (const uint8_t *)buffer;
2047
2048 while (writeOffset < len) {
2049 ssize_t written;
2050 do {
2051 written = write (fd, toWrite + writeOffset,
2052 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302053 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002054
2055 if (written >= 0) {
2056 writeOffset += written;
2057 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002058 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002059 close(fd);
2060 return -1;
2061 }
2062 }
2063
2064 return 0;
2065}
2066
2067static int
Etan Cohend3652192014-06-20 08:28:44 -07002068sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2069 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002070 int ret;
2071 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002072 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002073
Etan Cohend3652192014-06-20 08:28:44 -07002074 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2075
2076#if (SIM_COUNT >= 2)
2077 if (socket_id == RIL_SOCKET_2) {
2078 fd = s_ril_param_socket2.fdCommand;
2079 writeMutexHook = &s_writeMutex_socket2;
2080 }
2081#if (SIM_COUNT >= 3)
2082 else if (socket_id == RIL_SOCKET_3) {
2083 fd = s_ril_param_socket3.fdCommand;
2084 writeMutexHook = &s_writeMutex_socket3;
2085 }
2086#endif
2087#if (SIM_COUNT >= 4)
2088 else if (socket_id == RIL_SOCKET_4) {
2089 fd = s_ril_param_socket4.fdCommand;
2090 writeMutexHook = &s_writeMutex_socket4;
2091 }
2092#endif
2093#endif
2094 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002095 return -1;
2096 }
2097
2098 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002099 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2101
2102 return -1;
2103 }
Wink Saville7f856802009-06-09 10:23:37 -07002104
Etan Cohend3652192014-06-20 08:28:44 -07002105 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002106
2107 header = htonl(dataSize);
2108
2109 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2110
2111 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002112 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002113 return ret;
2114 }
2115
Kennyee1fadc2009-08-13 00:45:53 +08002116 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002117
2118 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002119 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002120 return ret;
2121 }
2122
Etan Cohend3652192014-06-20 08:28:44 -07002123 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124
2125 return 0;
2126}
2127
2128static int
Etan Cohend3652192014-06-20 08:28:44 -07002129sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002130 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002131 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132}
2133
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002134/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002135
2136static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002137responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002138 int numInts;
2139
2140 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002141 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002142 return RIL_ERRNO_INVALID_RESPONSE;
2143 }
2144 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002145 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002146 (int)responselen, (int)sizeof(int));
2147 return RIL_ERRNO_INVALID_RESPONSE;
2148 }
2149
2150 int *p_int = (int *) response;
2151
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002152 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002153 p.writeInt32 (numInts);
2154
2155 /* each int*/
2156 startResponse;
2157 for (int i = 0 ; i < numInts ; i++) {
2158 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2159 p.writeInt32(p_int[i]);
2160 }
2161 removeLastChar;
2162 closeResponse;
2163
2164 return 0;
2165}
2166
Wink Saville43808972011-01-13 17:39:51 -08002167/** response is a char **, pointing to an array of char *'s
2168 The parcel will begin with the version */
2169static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2170 p.writeInt32(version);
2171 return responseStrings(p, response, responselen);
2172}
2173
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002174/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002175static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002176 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002177
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002178 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002179 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002180 return RIL_ERRNO_INVALID_RESPONSE;
2181 }
2182 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002183 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002184 (int)responselen, (int)sizeof(char *));
2185 return RIL_ERRNO_INVALID_RESPONSE;
2186 }
2187
2188 if (response == NULL) {
2189 p.writeInt32 (0);
2190 } else {
2191 char **p_cur = (char **) response;
2192
2193 numStrings = responselen / sizeof(char *);
2194 p.writeInt32 (numStrings);
2195
2196 /* each string*/
2197 startResponse;
2198 for (int i = 0 ; i < numStrings ; i++) {
2199 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2200 writeStringToParcel (p, p_cur[i]);
2201 }
2202 removeLastChar;
2203 closeResponse;
2204 }
2205 return 0;
2206}
2207
2208
2209/**
Wink Saville7f856802009-06-09 10:23:37 -07002210 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002211 * FIXME currently ignores responselen
2212 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002213static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002214 /* one string only */
2215 startResponse;
2216 appendPrintBuf("%s%s", printBuf, (char*)response);
2217 closeResponse;
2218
2219 writeStringToParcel(p, (const char *)response);
2220
2221 return 0;
2222}
2223
Wink Savillef4c4d362009-04-02 01:37:03 -07002224static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002225 startResponse;
2226 removeLastChar;
2227 return 0;
2228}
2229
Wink Savillef4c4d362009-04-02 01:37:03 -07002230static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002231 int num;
2232
2233 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002234 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002235 return RIL_ERRNO_INVALID_RESPONSE;
2236 }
2237
2238 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002239 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002240 (int)responselen, (int)sizeof (RIL_Call *));
2241 return RIL_ERRNO_INVALID_RESPONSE;
2242 }
2243
2244 startResponse;
2245 /* number of call info's */
2246 num = responselen / sizeof(RIL_Call *);
2247 p.writeInt32(num);
2248
2249 for (int i = 0 ; i < num ; i++) {
2250 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2251 /* each call info */
2252 p.writeInt32(p_cur->state);
2253 p.writeInt32(p_cur->index);
2254 p.writeInt32(p_cur->toa);
2255 p.writeInt32(p_cur->isMpty);
2256 p.writeInt32(p_cur->isMT);
2257 p.writeInt32(p_cur->als);
2258 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002259 p.writeInt32(p_cur->isVoicePrivacy);
2260 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002261 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002262 writeStringToParcel(p, p_cur->name);
2263 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002264 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002265 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2266 p.writeInt32(0); /* UUS Information is absent */
2267 } else {
2268 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2269 p.writeInt32(1); /* UUS Information is present */
2270 p.writeInt32(uusInfo->uusType);
2271 p.writeInt32(uusInfo->uusDcs);
2272 p.writeInt32(uusInfo->uusLength);
2273 p.write(uusInfo->uusData, uusInfo->uusLength);
2274 }
Wink Saville3d54e742009-05-18 18:00:44 -07002275 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002276 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002277 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002278 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002279 p_cur->toa);
2280 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2281 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002282 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002283 (p_cur->isMT)?"mt":"mo",
2284 p_cur->als,
2285 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002286 (p_cur->isVoicePrivacy)?"evp":"noevp");
2287 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2288 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002289 p_cur->number,
2290 p_cur->numberPresentation,
2291 p_cur->name,
2292 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002293 }
2294 removeLastChar;
2295 closeResponse;
2296
2297 return 0;
2298}
2299
Wink Savillef4c4d362009-04-02 01:37:03 -07002300static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002301 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002302 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002303 return RIL_ERRNO_INVALID_RESPONSE;
2304 }
2305
2306 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002307 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002308 (int)responselen, (int)sizeof (RIL_SMS_Response));
2309 return RIL_ERRNO_INVALID_RESPONSE;
2310 }
2311
2312 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2313
2314 p.writeInt32(p_cur->messageRef);
2315 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002316 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002317
2318 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002319 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2320 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002321 closeResponse;
2322
2323 return 0;
2324}
2325
Wink Savillec0114b32011-02-18 10:14:07 -08002326static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002327{
2328 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002329 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002330 return RIL_ERRNO_INVALID_RESPONSE;
2331 }
2332
Wink Savillec0114b32011-02-18 10:14:07 -08002333 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002334 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002335 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002336 return RIL_ERRNO_INVALID_RESPONSE;
2337 }
2338
Amit Mahajan52500162014-07-29 17:36:48 -07002339 // Write version
2340 p.writeInt32(4);
2341
Wink Savillec0114b32011-02-18 10:14:07 -08002342 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002343 p.writeInt32(num);
2344
Wink Savillec0114b32011-02-18 10:14:07 -08002345 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002346 startResponse;
2347 int i;
2348 for (i = 0; i < num; i++) {
2349 p.writeInt32(p_cur[i].cid);
2350 p.writeInt32(p_cur[i].active);
2351 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002352 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002353 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002354 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002355 p_cur[i].cid,
2356 (p_cur[i].active==0)?"down":"up",
2357 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002358 (char*)p_cur[i].address);
2359 }
2360 removeLastChar;
2361 closeResponse;
2362
2363 return 0;
2364}
2365
Etan Cohend3652192014-06-20 08:28:44 -07002366static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2367{
Amit Mahajan52500162014-07-29 17:36:48 -07002368 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002369 RLOGE("invalid response: NULL");
2370 return RIL_ERRNO_INVALID_RESPONSE;
2371 }
2372
2373 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002374 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002375 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2376 return RIL_ERRNO_INVALID_RESPONSE;
2377 }
2378
Amit Mahajan52500162014-07-29 17:36:48 -07002379 // Write version
2380 p.writeInt32(6);
2381
Etan Cohend3652192014-06-20 08:28:44 -07002382 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2383 p.writeInt32(num);
2384
2385 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2386 startResponse;
2387 int i;
2388 for (i = 0; i < num; i++) {
2389 p.writeInt32((int)p_cur[i].status);
2390 p.writeInt32(p_cur[i].suggestedRetryTime);
2391 p.writeInt32(p_cur[i].cid);
2392 p.writeInt32(p_cur[i].active);
2393 writeStringToParcel(p, p_cur[i].type);
2394 writeStringToParcel(p, p_cur[i].ifname);
2395 writeStringToParcel(p, p_cur[i].addresses);
2396 writeStringToParcel(p, p_cur[i].dnses);
2397 writeStringToParcel(p, p_cur[i].gateways);
2398 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2399 p_cur[i].status,
2400 p_cur[i].suggestedRetryTime,
2401 p_cur[i].cid,
2402 (p_cur[i].active==0)?"down":"up",
2403 (char*)p_cur[i].type,
2404 (char*)p_cur[i].ifname,
2405 (char*)p_cur[i].addresses,
2406 (char*)p_cur[i].dnses,
2407 (char*)p_cur[i].gateways);
2408 }
2409 removeLastChar;
2410 closeResponse;
2411
2412 return 0;
2413}
2414
Wink Saville43808972011-01-13 17:39:51 -08002415static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2416{
Wink Saville43808972011-01-13 17:39:51 -08002417 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002418 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002419 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002420 } else {
2421 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002422 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002423 return RIL_ERRNO_INVALID_RESPONSE;
2424 }
2425
Etan Cohend3652192014-06-20 08:28:44 -07002426 // Support v6 or v9 with new rils
2427 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002428 RLOGD("responseDataCallList: v6");
Etan Cohend3652192014-06-20 08:28:44 -07002429 return responseDataCallListV6(p, response, responselen);
2430 }
2431
2432 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002433 RLOGE("responseDataCallList: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002434 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002435 return RIL_ERRNO_INVALID_RESPONSE;
2436 }
2437
Amit Mahajan52500162014-07-29 17:36:48 -07002438 // Write version
2439 p.writeInt32(10);
2440
Etan Cohend3652192014-06-20 08:28:44 -07002441 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002442 p.writeInt32(num);
2443
Etan Cohend3652192014-06-20 08:28:44 -07002444 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002445 startResponse;
2446 int i;
2447 for (i = 0; i < num; i++) {
2448 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002449 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002450 p.writeInt32(p_cur[i].cid);
2451 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002452 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002453 writeStringToParcel(p, p_cur[i].ifname);
2454 writeStringToParcel(p, p_cur[i].addresses);
2455 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002456 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002457 writeStringToParcel(p, p_cur[i].pcscf);
2458 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002459 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002460 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002461 p_cur[i].cid,
2462 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002463 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002464 (char*)p_cur[i].ifname,
2465 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002466 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002467 (char*)p_cur[i].gateways,
2468 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002469 }
2470 removeLastChar;
2471 closeResponse;
2472 }
2473
2474 return 0;
2475}
2476
2477static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2478{
2479 if (s_callbacks.version < 5) {
2480 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2481 } else {
2482 return responseDataCallList(p, response, responselen);
2483 }
2484}
2485
Wink Savillef4c4d362009-04-02 01:37:03 -07002486static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002487 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002488 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002489 return RIL_ERRNO_INVALID_RESPONSE;
2490 }
2491
2492 // The java code reads -1 size as null byte array
2493 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002494 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002495 } else {
2496 p.writeInt32(responselen);
2497 p.write(response, responselen);
2498 }
2499
2500 return 0;
2501}
2502
2503
Wink Savillef4c4d362009-04-02 01:37:03 -07002504static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002505 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002506 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002507 return RIL_ERRNO_INVALID_RESPONSE;
2508 }
2509
2510 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002511 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002512 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2513 return RIL_ERRNO_INVALID_RESPONSE;
2514 }
2515
2516 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2517 p.writeInt32(p_cur->sw1);
2518 p.writeInt32(p_cur->sw2);
2519 writeStringToParcel(p, p_cur->simResponse);
2520
2521 startResponse;
2522 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2523 (char*)p_cur->simResponse);
2524 closeResponse;
2525
2526
2527 return 0;
2528}
2529
Wink Savillef4c4d362009-04-02 01:37:03 -07002530static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002531 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002532
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002533 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002534 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002535 return RIL_ERRNO_INVALID_RESPONSE;
2536 }
2537
2538 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002539 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002540 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2541 return RIL_ERRNO_INVALID_RESPONSE;
2542 }
2543
2544 /* number of call info's */
2545 num = responselen / sizeof(RIL_CallForwardInfo *);
2546 p.writeInt32(num);
2547
2548 startResponse;
2549 for (int i = 0 ; i < num ; i++) {
2550 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2551
2552 p.writeInt32(p_cur->status);
2553 p.writeInt32(p_cur->reason);
2554 p.writeInt32(p_cur->serviceClass);
2555 p.writeInt32(p_cur->toa);
2556 writeStringToParcel(p, p_cur->number);
2557 p.writeInt32(p_cur->timeSeconds);
2558 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2559 (p_cur->status==1)?"enable":"disable",
2560 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2561 (char*)p_cur->number,
2562 p_cur->timeSeconds);
2563 }
2564 removeLastChar;
2565 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002566
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002567 return 0;
2568}
2569
Wink Savillef4c4d362009-04-02 01:37:03 -07002570static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002571 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002572 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002573 return RIL_ERRNO_INVALID_RESPONSE;
2574 }
2575
2576 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002577 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002578 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2579 return RIL_ERRNO_INVALID_RESPONSE;
2580 }
2581
2582 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2583 p.writeInt32(p_cur->notificationType);
2584 p.writeInt32(p_cur->code);
2585 p.writeInt32(p_cur->index);
2586 p.writeInt32(p_cur->type);
2587 writeStringToParcel(p, p_cur->number);
2588
2589 startResponse;
2590 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2591 (p_cur->notificationType==0)?"mo":"mt",
2592 p_cur->code, p_cur->index, p_cur->type,
2593 (char*)p_cur->number);
2594 closeResponse;
2595
2596 return 0;
2597}
2598
Wink Saville3d54e742009-05-18 18:00:44 -07002599static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002600 int num;
2601
2602 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002603 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002604 return RIL_ERRNO_INVALID_RESPONSE;
2605 }
2606
2607 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002608 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002609 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2610 return RIL_ERRNO_INVALID_RESPONSE;
2611 }
2612
2613 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002614 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002615 num = responselen / sizeof(RIL_NeighboringCell *);
2616 p.writeInt32(num);
2617
2618 for (int i = 0 ; i < num ; i++) {
2619 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2620
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002621 p.writeInt32(p_cur->rssi);
2622 writeStringToParcel (p, p_cur->cid);
2623
2624 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2625 p_cur->cid, p_cur->rssi);
2626 }
2627 removeLastChar;
2628 closeResponse;
2629
2630 return 0;
2631}
2632
Wink Saville3d54e742009-05-18 18:00:44 -07002633/**
2634 * Marshall the signalInfoRecord into the parcel if it exists.
2635 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002636static void marshallSignalInfoRecord(Parcel &p,
2637 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002638 p.writeInt32(p_signalInfoRecord.isPresent);
2639 p.writeInt32(p_signalInfoRecord.signalType);
2640 p.writeInt32(p_signalInfoRecord.alertPitch);
2641 p.writeInt32(p_signalInfoRecord.signal);
2642}
2643
Wink Savillea592eeb2009-05-22 13:26:36 -07002644static int responseCdmaInformationRecords(Parcel &p,
2645 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002646 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002647 char* string8 = NULL;
2648 int buffer_lenght;
2649 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002650
2651 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002652 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002653 return RIL_ERRNO_INVALID_RESPONSE;
2654 }
2655
Wink Savillea592eeb2009-05-22 13:26:36 -07002656 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002657 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002658 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002659 return RIL_ERRNO_INVALID_RESPONSE;
2660 }
2661
Wink Savillea592eeb2009-05-22 13:26:36 -07002662 RIL_CDMA_InformationRecords *p_cur =
2663 (RIL_CDMA_InformationRecords *) response;
2664 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002665
2666 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002667 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002668
Wink Savillea592eeb2009-05-22 13:26:36 -07002669 for (int i = 0 ; i < num ; i++) {
2670 infoRec = &p_cur->infoRec[i];
2671 p.writeInt32(infoRec->name);
2672 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002673 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002674 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2675 if (infoRec->rec.display.alpha_len >
2676 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002677 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002678 expected not more than %d\n",
2679 (int)infoRec->rec.display.alpha_len,
2680 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2681 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002682 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002683 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2684 * sizeof(char) );
2685 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2686 string8[i] = infoRec->rec.display.alpha_buf[i];
2687 }
Wink Saville43808972011-01-13 17:39:51 -08002688 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002689 writeStringToParcel(p, (const char*)string8);
2690 free(string8);
2691 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002692 break;
2693 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002694 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002695 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002696 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002697 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002698 expected not more than %d\n",
2699 (int)infoRec->rec.number.len,
2700 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2701 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002702 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002703 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2704 * sizeof(char) );
2705 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2706 string8[i] = infoRec->rec.number.buf[i];
2707 }
Wink Saville43808972011-01-13 17:39:51 -08002708 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002709 writeStringToParcel(p, (const char*)string8);
2710 free(string8);
2711 string8 = NULL;
2712 p.writeInt32(infoRec->rec.number.number_type);
2713 p.writeInt32(infoRec->rec.number.number_plan);
2714 p.writeInt32(infoRec->rec.number.pi);
2715 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002716 break;
2717 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002718 p.writeInt32(infoRec->rec.signal.isPresent);
2719 p.writeInt32(infoRec->rec.signal.signalType);
2720 p.writeInt32(infoRec->rec.signal.alertPitch);
2721 p.writeInt32(infoRec->rec.signal.signal);
2722
2723 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2724 alertPitch=%X, signal=%X, ",
2725 printBuf, (int)infoRec->rec.signal.isPresent,
2726 (int)infoRec->rec.signal.signalType,
2727 (int)infoRec->rec.signal.alertPitch,
2728 (int)infoRec->rec.signal.signal);
2729 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002730 break;
2731 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002732 if (infoRec->rec.redir.redirectingNumber.len >
2733 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002734 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002735 expected not more than %d\n",
2736 (int)infoRec->rec.redir.redirectingNumber.len,
2737 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2738 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002739 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002740 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2741 .len + 1) * sizeof(char) );
2742 for (int i = 0;
2743 i < infoRec->rec.redir.redirectingNumber.len;
2744 i++) {
2745 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2746 }
Wink Saville43808972011-01-13 17:39:51 -08002747 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002748 writeStringToParcel(p, (const char*)string8);
2749 free(string8);
2750 string8 = NULL;
2751 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2752 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2753 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2754 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2755 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002756 break;
2757 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002758 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2759 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2760 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2761 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2762
2763 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2764 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2765 lineCtrlPowerDenial=%d, ", printBuf,
2766 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2767 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2768 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2769 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2770 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002771 break;
2772 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002773 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002774
Wink Savillea592eeb2009-05-22 13:26:36 -07002775 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2776 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002777 break;
2778 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002779 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2780 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2781
2782 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2783 infoRec->rec.audioCtrl.upLink,
2784 infoRec->rec.audioCtrl.downLink);
2785 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002786 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002787 case RIL_CDMA_T53_RELEASE_INFO_REC:
2788 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002789 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002790 return RIL_ERRNO_INVALID_RESPONSE;
2791 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002792 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002793 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002794 }
2795 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002796 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002797
Wink Savillea592eeb2009-05-22 13:26:36 -07002798 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002799}
2800
Wink Savillea592eeb2009-05-22 13:26:36 -07002801static int responseRilSignalStrength(Parcel &p,
2802 void *response, size_t responselen) {
2803 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002804 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002805 return RIL_ERRNO_INVALID_RESPONSE;
2806 }
2807
Wink Savillec0114b32011-02-18 10:14:07 -08002808 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002809 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002810
Wink Saville3d54e742009-05-18 18:00:44 -07002811 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2812 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2813 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2814 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2815 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2816 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2817 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002818 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002819 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002820 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002821 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002822 if (s_callbacks.version <= 6) {
2823 // signalStrength: -1 -> 99
2824 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2825 p_cur->LTE_SignalStrength.signalStrength = 99;
2826 }
2827 // rsrp: -1 -> INT_MAX all other negative value to positive.
2828 // So remap here
2829 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2830 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2831 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2832 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2833 }
2834 // rsrq: -1 -> INT_MAX
2835 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2836 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2837 }
2838 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002839
Wink Saville18e4ab12013-04-07 17:31:04 -07002840 // cqi: -1 -> INT_MAX
2841 if (p_cur->LTE_SignalStrength.cqi == -1) {
2842 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2843 }
2844 }
2845 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002846 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2847 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2848 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2849 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002850 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2851 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2852 } else {
2853 p.writeInt32(INT_MAX);
2854 }
Wink Savillec0114b32011-02-18 10:14:07 -08002855 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002856 p.writeInt32(99);
2857 p.writeInt32(INT_MAX);
2858 p.writeInt32(INT_MAX);
2859 p.writeInt32(INT_MAX);
2860 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002861 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002862 }
johnwangfdf825f2009-05-22 15:50:34 -07002863
2864 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002865 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002866 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2867 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2868 EVDO_SS.signalNoiseRatio=%d,\
2869 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002870 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002871 printBuf,
2872 p_cur->GW_SignalStrength.signalStrength,
2873 p_cur->GW_SignalStrength.bitErrorRate,
2874 p_cur->CDMA_SignalStrength.dbm,
2875 p_cur->CDMA_SignalStrength.ecio,
2876 p_cur->EVDO_SignalStrength.dbm,
2877 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002878 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2879 p_cur->LTE_SignalStrength.signalStrength,
2880 p_cur->LTE_SignalStrength.rsrp,
2881 p_cur->LTE_SignalStrength.rsrq,
2882 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002883 p_cur->LTE_SignalStrength.cqi,
2884 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002885 closeResponse;
2886
Wink Saville3d54e742009-05-18 18:00:44 -07002887 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002888 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002889 return RIL_ERRNO_INVALID_RESPONSE;
2890 }
2891
Wink Saville3d54e742009-05-18 18:00:44 -07002892 return 0;
2893}
2894
2895static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2896 if ((response == NULL) || (responselen == 0)) {
2897 return responseVoid(p, response, responselen);
2898 } else {
2899 return responseCdmaSignalInfoRecord(p, response, responselen);
2900 }
2901}
2902
2903static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2904 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002905 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002906 return RIL_ERRNO_INVALID_RESPONSE;
2907 }
2908
2909 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002910 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002911 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2912 return RIL_ERRNO_INVALID_RESPONSE;
2913 }
2914
2915 startResponse;
2916
2917 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2918 marshallSignalInfoRecord(p, *p_cur);
2919
2920 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2921 signal=%d]",
2922 printBuf,
2923 p_cur->isPresent,
2924 p_cur->signalType,
2925 p_cur->alertPitch,
2926 p_cur->signal);
2927
2928 closeResponse;
2929 return 0;
2930}
2931
Wink Savillea592eeb2009-05-22 13:26:36 -07002932static int responseCdmaCallWaiting(Parcel &p, void *response,
2933 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002934 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002935 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002936 return RIL_ERRNO_INVALID_RESPONSE;
2937 }
2938
Wink Savillec0114b32011-02-18 10:14:07 -08002939 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002940 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002941 }
2942
2943 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2944
2945 writeStringToParcel(p, p_cur->number);
2946 p.writeInt32(p_cur->numberPresentation);
2947 writeStringToParcel(p, p_cur->name);
2948 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2949
2950 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2951 p.writeInt32(p_cur->number_type);
2952 p.writeInt32(p_cur->number_plan);
2953 } else {
2954 p.writeInt32(0);
2955 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002956 }
2957
2958 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002959 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2960 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002961 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002962 printBuf,
2963 p_cur->number,
2964 p_cur->numberPresentation,
2965 p_cur->name,
2966 p_cur->signalInfoRecord.isPresent,
2967 p_cur->signalInfoRecord.signalType,
2968 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002969 p_cur->signalInfoRecord.signal,
2970 p_cur->number_type,
2971 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002972 closeResponse;
2973
2974 return 0;
2975}
2976
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002977static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2978 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002979 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002980 return RIL_ERRNO_INVALID_RESPONSE;
2981 }
2982
2983 startResponse;
2984 if (s_callbacks.version == 7) {
2985 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2986 p.writeInt32(p_cur->result);
2987 p.writeInt32(p_cur->ef_id);
2988 writeStringToParcel(p, p_cur->aid);
2989
2990 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2991 printBuf,
2992 p_cur->result,
2993 p_cur->ef_id,
2994 p_cur->aid);
2995 } else {
2996 int *p_cur = ((int *) response);
2997 p.writeInt32(p_cur[0]);
2998 p.writeInt32(p_cur[1]);
2999 writeStringToParcel(p, NULL);
3000
3001 appendPrintBuf("%sresult=%d, ef_id=%d",
3002 printBuf,
3003 p_cur[0],
3004 p_cur[1]);
3005 }
3006 closeResponse;
3007
3008 return 0;
3009}
3010
Wink Saville8a9e0212013-04-09 12:11:38 -07003011static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3012{
3013 if (response == NULL && responselen != 0) {
3014 RLOGE("invalid response: NULL");
3015 return RIL_ERRNO_INVALID_RESPONSE;
3016 }
3017
3018 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003019 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003020 (int)responselen, (int)sizeof(RIL_CellInfo));
3021 return RIL_ERRNO_INVALID_RESPONSE;
3022 }
3023
3024 int num = responselen / sizeof(RIL_CellInfo);
3025 p.writeInt32(num);
3026
3027 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3028 startResponse;
3029 int i;
3030 for (i = 0; i < num; i++) {
3031 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3032 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3033 p.writeInt32((int)p_cur->cellInfoType);
3034 p.writeInt32(p_cur->registered);
3035 p.writeInt32(p_cur->timeStampType);
3036 p.writeInt64(p_cur->timeStamp);
3037 switch(p_cur->cellInfoType) {
3038 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003039 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003040 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3041 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3042 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003043 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3044 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003045 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3046 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3047
3048 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3049 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3050 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3051 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003052 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3053 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3054 break;
3055 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003056 case RIL_CELL_INFO_TYPE_WCDMA: {
3057 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3058 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3059 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3060 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3061 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3062 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3063 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3064 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3065 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3066
3067 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3068 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3069 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3070 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3071 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3072 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3073 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3074 break;
3075 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003076 case RIL_CELL_INFO_TYPE_CDMA: {
3077 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3078 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3079 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3080 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3081 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3082 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3083
3084 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3085 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3086 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3087 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3088 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3089
3090 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3091 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3092 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3093 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3094 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3095 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3096
3097 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3098 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3099 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3100 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3101 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3102 break;
3103 }
3104 case RIL_CELL_INFO_TYPE_LTE: {
3105 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3106 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3107 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3108 p_cur->CellInfo.lte.cellIdentityLte.ci,
3109 p_cur->CellInfo.lte.cellIdentityLte.pci,
3110 p_cur->CellInfo.lte.cellIdentityLte.tac);
3111
3112 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3113 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3114 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3115 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3116 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3117
3118 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3119 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3120 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3121 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3122 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3123 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3124 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3125 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3126 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3127 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3128 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3129 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3130 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3131 break;
3132 }
Etan Cohend3652192014-06-20 08:28:44 -07003133 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3134 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3135 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3136 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3137 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3138 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3139 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3140 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3141 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3142
3143 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3144 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3145 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3146 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3147 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3148 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3149 break;
3150 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003151 }
3152 p_cur += 1;
3153 }
3154 removeLastChar;
3155 closeResponse;
3156
3157 return 0;
3158}
3159
Etan Cohend3652192014-06-20 08:28:44 -07003160static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3161{
3162 if (response == NULL && responselen != 0) {
3163 RLOGE("invalid response: NULL");
3164 return RIL_ERRNO_INVALID_RESPONSE;
3165 }
3166
3167 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003168 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003169 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3170 return RIL_ERRNO_INVALID_RESPONSE;
3171 }
3172
3173 int num = responselen / sizeof(RIL_HardwareConfig);
3174 int i;
3175 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3176
3177 p.writeInt32(num);
3178
3179 startResponse;
3180 for (i = 0; i < num; i++) {
3181 switch (p_cur[i].type) {
3182 case RIL_HARDWARE_CONFIG_MODEM: {
3183 writeStringToParcel(p, p_cur[i].uuid);
3184 p.writeInt32((int)p_cur[i].state);
3185 p.writeInt32(p_cur[i].cfg.modem.rat);
3186 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3187 p.writeInt32(p_cur[i].cfg.modem.maxData);
3188 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3189
3190 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3191 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3192 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3193 break;
3194 }
3195 case RIL_HARDWARE_CONFIG_SIM: {
3196 writeStringToParcel(p, p_cur[i].uuid);
3197 p.writeInt32((int)p_cur[i].state);
3198 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3199
3200 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3201 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3202 break;
3203 }
3204 }
3205 }
3206 removeLastChar;
3207 closeResponse;
3208 return 0;
3209}
3210
Wink Saville8b4e4f72014-10-17 15:01:45 -07003211static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3212 if (response == NULL) {
3213 RLOGE("invalid response: NULL");
3214 return RIL_ERRNO_INVALID_RESPONSE;
3215 }
3216
3217 if (responselen != sizeof (RIL_RadioCapability) ) {
3218 RLOGE("invalid response length was %d expected %d",
3219 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3220 return RIL_ERRNO_INVALID_RESPONSE;
3221 }
3222
3223 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3224 p.writeInt32(p_cur->version);
3225 p.writeInt32(p_cur->session);
3226 p.writeInt32(p_cur->phase);
3227 p.writeInt32(p_cur->rat);
3228 writeStringToParcel(p, p_cur->logicalModemUuid);
3229 p.writeInt32(p_cur->status);
3230
3231 startResponse;
3232 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003233 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003234 printBuf,
3235 p_cur->version,
3236 p_cur->session,
3237 p_cur->phase,
3238 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003239 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003240 p_cur->status);
3241 closeResponse;
3242 return 0;
3243}
3244
Amit Mahajan54563d32014-11-22 00:54:49 +00003245static int responseSSData(Parcel &p, void *response, size_t responselen) {
3246 RLOGD("In responseSSData");
3247 int num;
3248
3249 if (response == NULL && responselen != 0) {
3250 RLOGE("invalid response length was %d expected %d",
3251 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3252 return RIL_ERRNO_INVALID_RESPONSE;
3253 }
3254
3255 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3256 RLOGE("invalid response length %d, expected %d",
3257 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3258 return RIL_ERRNO_INVALID_RESPONSE;
3259 }
3260
3261 startResponse;
3262 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3263 p.writeInt32(p_cur->serviceType);
3264 p.writeInt32(p_cur->requestType);
3265 p.writeInt32(p_cur->teleserviceType);
3266 p.writeInt32(p_cur->serviceClass);
3267 p.writeInt32(p_cur->result);
3268
3269 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3270 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3271 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3272 RLOGE("numValidIndexes is greater than max value %d, "
3273 "truncating it to max value", NUM_SERVICE_CLASSES);
3274 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3275 }
3276 /* number of call info's */
3277 p.writeInt32(p_cur->cfData.numValidIndexes);
3278
3279 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3280 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3281
3282 p.writeInt32(cf.status);
3283 p.writeInt32(cf.reason);
3284 p.writeInt32(cf.serviceClass);
3285 p.writeInt32(cf.toa);
3286 writeStringToParcel(p, cf.number);
3287 p.writeInt32(cf.timeSeconds);
3288 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3289 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3290 (char*)cf.number, cf.timeSeconds);
3291 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3292 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3293 }
3294 } else {
3295 p.writeInt32 (SS_INFO_MAX);
3296
3297 /* each int*/
3298 for (int i = 0; i < SS_INFO_MAX; i++) {
3299 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3300 RLOGD("Data: %d",p_cur->ssInfo[i]);
3301 p.writeInt32(p_cur->ssInfo[i]);
3302 }
3303 }
3304 removeLastChar;
3305 closeResponse;
3306
3307 return 0;
3308}
3309
3310static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3311 if ((reqType == SS_INTERROGATION) &&
3312 (serType == SS_CFU ||
3313 serType == SS_CF_BUSY ||
3314 serType == SS_CF_NO_REPLY ||
3315 serType == SS_CF_NOT_REACHABLE ||
3316 serType == SS_CF_ALL ||
3317 serType == SS_CF_ALL_CONDITIONAL)) {
3318 return true;
3319 }
3320 return false;
3321}
3322
Wink Saville3d54e742009-05-18 18:00:44 -07003323static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003324 int ret;
3325 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3326 /* trigger event loop to wakeup. No reason to do this,
3327 * if we're in the event loop thread */
3328 do {
3329 ret = write (s_fdWakeupWrite, " ", 1);
3330 } while (ret < 0 && errno == EINTR);
3331 }
3332}
3333
Wink Saville3d54e742009-05-18 18:00:44 -07003334static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003335 ril_event_add(ev);
3336 triggerEvLoop();
3337}
3338
Wink Savillefd729372011-02-22 16:19:39 -08003339static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3340 p.writeInt32(num_apps);
3341 startResponse;
3342 for (int i = 0; i < num_apps; i++) {
3343 p.writeInt32(appStatus[i].app_type);
3344 p.writeInt32(appStatus[i].app_state);
3345 p.writeInt32(appStatus[i].perso_substate);
3346 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3347 writeStringToParcel(p, (const char*)
3348 (appStatus[i].app_label_ptr));
3349 p.writeInt32(appStatus[i].pin1_replaced);
3350 p.writeInt32(appStatus[i].pin1);
3351 p.writeInt32(appStatus[i].pin2);
3352 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3353 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3354 printBuf,
3355 appStatus[i].app_type,
3356 appStatus[i].app_state,
3357 appStatus[i].perso_substate,
3358 appStatus[i].aid_ptr,
3359 appStatus[i].app_label_ptr,
3360 appStatus[i].pin1_replaced,
3361 appStatus[i].pin1,
3362 appStatus[i].pin2);
3363 }
3364 closeResponse;
3365}
3366
Wink Savillef4c4d362009-04-02 01:37:03 -07003367static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3368 int i;
3369
3370 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003371 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003372 return RIL_ERRNO_INVALID_RESPONSE;
3373 }
3374
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003375 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003376 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003377
Wink Savillefd729372011-02-22 16:19:39 -08003378 p.writeInt32(p_cur->card_state);
3379 p.writeInt32(p_cur->universal_pin_state);
3380 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3381 p.writeInt32(p_cur->cdma_subscription_app_index);
3382 p.writeInt32(p_cur->ims_subscription_app_index);
3383
3384 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003385 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003386 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3387
3388 p.writeInt32(p_cur->card_state);
3389 p.writeInt32(p_cur->universal_pin_state);
3390 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3391 p.writeInt32(p_cur->cdma_subscription_app_index);
3392 p.writeInt32(-1);
3393
3394 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003395 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003396 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003397 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003398 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003399
3400 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003401}
Wink Savillef4c4d362009-04-02 01:37:03 -07003402
Wink Savillea592eeb2009-05-22 13:26:36 -07003403static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3404 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003405 p.writeInt32(num);
3406
Wink Savillef4c4d362009-04-02 01:37:03 -07003407 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003408 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3409 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3410 for (int i = 0; i < num; i++) {
3411 p.writeInt32(p_cur[i]->fromServiceId);
3412 p.writeInt32(p_cur[i]->toServiceId);
3413 p.writeInt32(p_cur[i]->fromCodeScheme);
3414 p.writeInt32(p_cur[i]->toCodeScheme);
3415 p.writeInt32(p_cur[i]->selected);
3416
3417 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3418 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3419 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3420 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3421 p_cur[i]->selected);
3422 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003423 closeResponse;
3424
3425 return 0;
3426}
3427
Wink Savillea592eeb2009-05-22 13:26:36 -07003428static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3429 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3430 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003431
Wink Savillea592eeb2009-05-22 13:26:36 -07003432 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3433 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003434
3435 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003436 for (int i = 0 ; i < num ; i++ ) {
3437 p.writeInt32(p_cur[i]->service_category);
3438 p.writeInt32(p_cur[i]->language);
3439 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003440
Wink Savillea592eeb2009-05-22 13:26:36 -07003441 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3442 selected =%d], ",
3443 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3444 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003445 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003446 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003447
Wink Savillef4c4d362009-04-02 01:37:03 -07003448 return 0;
3449}
3450
3451static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3452 int num;
3453 int digitCount;
3454 int digitLimit;
3455 uint8_t uct;
3456 void* dest;
3457
Wink Saville8eb2a122012-11-19 16:05:13 -08003458 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003459
Wink Savillef4c4d362009-04-02 01:37:03 -07003460 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003461 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003462 return RIL_ERRNO_INVALID_RESPONSE;
3463 }
3464
Wink Savillef5903df2009-04-24 11:54:14 -07003465 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003466 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003467 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003468 return RIL_ERRNO_INVALID_RESPONSE;
3469 }
3470
3471 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3472 p.writeInt32(p_cur->uTeleserviceID);
3473 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3474 p.writeInt32(p_cur->uServicecategory);
3475 p.writeInt32(p_cur->sAddress.digit_mode);
3476 p.writeInt32(p_cur->sAddress.number_mode);
3477 p.writeInt32(p_cur->sAddress.number_type);
3478 p.writeInt32(p_cur->sAddress.number_plan);
3479 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3480 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3481 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3482 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3483 }
3484
3485 p.writeInt32(p_cur->sSubAddress.subaddressType);
3486 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3487 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3488 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3489 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3490 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3491 }
3492
3493 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3494 p.writeInt32(p_cur->uBearerDataLen);
3495 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3496 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3497 }
3498
3499 startResponse;
3500 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003501 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003502 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3503 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3504 closeResponse;
3505
3506 return 0;
3507}
3508
Wink Savillec29360a2014-07-13 05:17:28 -07003509static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3510{
3511 int num = responselen / sizeof(RIL_DcRtInfo);
3512 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003513 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003514 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3515 return RIL_ERRNO_INVALID_RESPONSE;
3516 }
3517
3518 startResponse;
3519 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3520 p.writeInt64(pDcRtInfo->time);
3521 p.writeInt32(pDcRtInfo->powerState);
3522 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3523 pDcRtInfo->time,
3524 pDcRtInfo->powerState);
3525 closeResponse;
3526
3527 return 0;
3528}
3529
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003530/**
3531 * A write on the wakeup fd is done just to pop us out of select()
3532 * We empty the buffer here and then ril_event will reset the timers on the
3533 * way back down
3534 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003535static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003536 char buff[16];
3537 int ret;
3538
Wink Saville8eb2a122012-11-19 16:05:13 -08003539 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003540
3541 /* empty our wakeup socket out */
3542 do {
3543 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003544 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003545}
3546
Etan Cohend3652192014-06-20 08:28:44 -07003547static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003548 int ret;
3549 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003550 /* Hook for current context
3551 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3552 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3553 /* pendingRequestsHook refer to &s_pendingRequests */
3554 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003555
Etan Cohend3652192014-06-20 08:28:44 -07003556#if (SIM_COUNT >= 2)
3557 if (socket_id == RIL_SOCKET_2) {
3558 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3559 pendingRequestsHook = &s_pendingRequests_socket2;
3560 }
3561#if (SIM_COUNT >= 3)
3562 else if (socket_id == RIL_SOCKET_3) {
3563 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3564 pendingRequestsHook = &s_pendingRequests_socket3;
3565 }
3566#endif
3567#if (SIM_COUNT >= 4)
3568 else if (socket_id == RIL_SOCKET_4) {
3569 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3570 pendingRequestsHook = &s_pendingRequests_socket4;
3571 }
3572#endif
3573#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003574 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003575 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003576 assert (ret == 0);
3577
Etan Cohend3652192014-06-20 08:28:44 -07003578 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003579
Etan Cohend3652192014-06-20 08:28:44 -07003580 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003581 ; p_cur != NULL
3582 ; p_cur = p_cur->p_next
3583 ) {
3584 p_cur->cancelled = 1;
3585 }
3586
Etan Cohend3652192014-06-20 08:28:44 -07003587 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003588 assert (ret == 0);
3589}
3590
Wink Savillef4c4d362009-04-02 01:37:03 -07003591static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003592 RecordStream *p_rs;
3593 void *p_record;
3594 size_t recordlen;
3595 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003596 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003597
Etan Cohend3652192014-06-20 08:28:44 -07003598 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003599
Etan Cohend3652192014-06-20 08:28:44 -07003600 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003601
3602 for (;;) {
3603 /* loop until EAGAIN/EINTR, end of stream, or other error */
3604 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3605
3606 if (ret == 0 && p_record == NULL) {
3607 /* end-of-stream */
3608 break;
3609 } else if (ret < 0) {
3610 break;
3611 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003612 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003613 }
3614 }
3615
3616 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3617 /* fatal error or end-of-stream */
3618 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003619 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003620 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003621 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003622 }
Wink Saville7f856802009-06-09 10:23:37 -07003623
Etan Cohend3652192014-06-20 08:28:44 -07003624 close(fd);
3625 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003626
Etan Cohend3652192014-06-20 08:28:44 -07003627 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003628
3629 record_stream_free(p_rs);
3630
3631 /* start listening for new connections again */
3632 rilEventAddWakeup(&s_listen_event);
3633
Etan Cohend3652192014-06-20 08:28:44 -07003634 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003635 }
3636}
3637
3638
Etan Cohend3652192014-06-20 08:28:44 -07003639static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003640 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003641 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003642 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3643 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003644
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003645 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003646 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3647 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003648
3649 // Send last NITZ time data, in case it was missed
3650 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003651 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003652
3653 free(s_lastNITZTimeData);
3654 s_lastNITZTimeData = NULL;
3655 }
3656
3657 // Get version string
3658 if (s_callbacks.getVersion != NULL) {
3659 const char *version;
3660 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003661 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003662
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003663 property_set(PROPERTY_RIL_IMPL, version);
3664 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003665 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003666 property_set(PROPERTY_RIL_IMPL, "unavailable");
3667 }
3668
3669}
3670
Wink Savillef4c4d362009-04-02 01:37:03 -07003671static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003672 int ret;
3673 int err;
3674 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003675 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003676 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003677 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003678
3679 struct sockaddr_un peeraddr;
3680 socklen_t socklen = sizeof (peeraddr);
3681
3682 struct ucred creds;
3683 socklen_t szCreds = sizeof(creds);
3684
3685 struct passwd *pwd = NULL;
3686
Etan Cohend3652192014-06-20 08:28:44 -07003687 assert (*p_info->fdCommand < 0);
3688 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003689
Etan Cohend3652192014-06-20 08:28:44 -07003690 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003691
Etan Cohend3652192014-06-20 08:28:44 -07003692 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003693 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003694 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003695 rilEventAddWakeup(p_info->listen_event);
3696 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003697 }
3698
3699 /* check the credential of the other side and only accept socket from
3700 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003701 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003702 errno = 0;
3703 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003704
Etan Cohend3652192014-06-20 08:28:44 -07003705 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003706
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003707 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003708 errno = 0;
3709 pwd = getpwuid(creds.uid);
3710 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003711 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003712 is_phone_socket = 1;
3713 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003714 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003715 }
3716 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003717 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003718 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003719 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003720 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003721 }
3722
Etan Cohend3652192014-06-20 08:28:44 -07003723 if (!is_phone_socket) {
3724 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003725
Etan Cohend3652192014-06-20 08:28:44 -07003726 close(fdCommand);
3727 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003728
Etan Cohend3652192014-06-20 08:28:44 -07003729 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003730
3731 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003732 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003733
3734 return;
3735 }
3736
Etan Cohend3652192014-06-20 08:28:44 -07003737 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003738
3739 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003740 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003741 }
3742
Etan Cohend3652192014-06-20 08:28:44 -07003743 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003744
Etan Cohend3652192014-06-20 08:28:44 -07003745 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003746
Etan Cohend3652192014-06-20 08:28:44 -07003747 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003748
Etan Cohend3652192014-06-20 08:28:44 -07003749 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003750
Etan Cohend3652192014-06-20 08:28:44 -07003751 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3752 p_info->processCommandsCallback, p_info);
3753
3754 rilEventAddWakeup (p_info->commands_event);
3755
3756 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003757}
3758
3759static void freeDebugCallbackArgs(int number, char **args) {
3760 for (int i = 0; i < number; i++) {
3761 if (args[i] != NULL) {
3762 free(args[i]);
3763 }
3764 }
3765 free(args);
3766}
3767
Wink Savillef4c4d362009-04-02 01:37:03 -07003768static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003769 int acceptFD, option;
3770 struct sockaddr_un peeraddr;
3771 socklen_t socklen = sizeof (peeraddr);
3772 int data;
3773 unsigned int qxdm_data[6];
3774 const char *deactData[1] = {"1"};
3775 char *actData[1];
3776 RIL_Dial dialData;
3777 int hangupData[1] = {1};
3778 int number;
3779 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003780 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3781 int sim_id = 0;
3782
3783 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003784
3785 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3786
3787 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003788 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003789 return;
3790 }
3791
3792 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003793 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003794 return;
3795 }
3796 args = (char **) malloc(sizeof(char*) * number);
3797
3798 for (int i = 0; i < number; i++) {
3799 int len;
3800 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003801 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003802 freeDebugCallbackArgs(i, args);
3803 return;
3804 }
3805 // +1 for null-term
3806 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003807 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003808 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003809 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003810 freeDebugCallbackArgs(i, args);
3811 return;
3812 }
3813 char * buf = args[i];
3814 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003815 if ((i+1) == number) {
3816 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3817 sim_id = atoi(args[i]);
3818 switch (sim_id) {
3819 case 0:
3820 socket_id = RIL_SOCKET_1;
3821 break;
3822 #if (SIM_COUNT >= 2)
3823 case 1:
3824 socket_id = RIL_SOCKET_2;
3825 break;
3826 #endif
3827 #if (SIM_COUNT >= 3)
3828 case 2:
3829 socket_id = RIL_SOCKET_3;
3830 break;
3831 #endif
3832 #if (SIM_COUNT >= 4)
3833 case 3:
3834 socket_id = RIL_SOCKET_4;
3835 break;
3836 #endif
3837 default:
3838 socket_id = RIL_SOCKET_1;
3839 break;
3840 }
3841 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003842 }
3843
3844 switch (atoi(args[0])) {
3845 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003846 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003847 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003848 break;
3849 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003850 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003851 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003852 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003853 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003854 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3855 close(s_ril_param_socket.fdCommand);
3856 s_ril_param_socket.fdCommand = -1;
3857 }
3858 #if (SIM_COUNT == 2)
3859 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3860 close(s_ril_param_socket2.fdCommand);
3861 s_ril_param_socket2.fdCommand = -1;
3862 }
3863 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003864 break;
3865 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003866 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003867 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003868 break;
3869 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003870 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003871 qxdm_data[0] = 65536; // head.func_tag
3872 qxdm_data[1] = 16; // head.len
3873 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3874 qxdm_data[3] = 32; // log_file_size: 32megabytes
3875 qxdm_data[4] = 0; // log_mask
3876 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003877 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003878 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003879 break;
3880 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003881 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003882 qxdm_data[0] = 65536;
3883 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003884 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003885 qxdm_data[3] = 32;
3886 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003887 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003888 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003889 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003890 break;
3891 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003892 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003893 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003894 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003895 sleep(2);
3896 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003897 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003898 break;
3899 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003900 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003901 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003902 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003903 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003904 break;
3905 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003906 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003907 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003908 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003909 break;
3910 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003911 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003912 dialData.clir = 0;
3913 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003914 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003915 break;
3916 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003917 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003918 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003919 break;
3920 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003921 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003922 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003923 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003924 break;
3925 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003926 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003927 break;
3928 }
3929 freeDebugCallbackArgs(number, args);
3930 close(acceptFD);
3931}
3932
3933
Wink Savillef4c4d362009-04-02 01:37:03 -07003934static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003935 UserCallbackInfo *p_info;
3936
3937 p_info = (UserCallbackInfo *)param;
3938
3939 p_info->p_callback(p_info->userParam);
3940
3941
3942 // FIXME generalize this...there should be a cancel mechanism
3943 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3944 s_last_wake_timeout_info = NULL;
3945 }
3946
3947 free(p_info);
3948}
3949
3950
3951static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003952eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003953 int ret;
3954 int filedes[2];
3955
3956 ril_event_init();
3957
3958 pthread_mutex_lock(&s_startupMutex);
3959
3960 s_started = 1;
3961 pthread_cond_broadcast(&s_startupCond);
3962
3963 pthread_mutex_unlock(&s_startupMutex);
3964
3965 ret = pipe(filedes);
3966
3967 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003968 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003969 return NULL;
3970 }
3971
3972 s_fdWakeupRead = filedes[0];
3973 s_fdWakeupWrite = filedes[1];
3974
3975 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3976
3977 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3978 processWakeupCallback, NULL);
3979
3980 rilEventAddWakeup (&s_wakeupfd_event);
3981
3982 // Only returns on error
3983 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003984 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003985 // kill self to restart on error
3986 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003987
3988 return NULL;
3989}
3990
Wink Saville7f856802009-06-09 10:23:37 -07003991extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003992RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003993 /* spin up eventLoop thread and wait for it to get started */
3994 s_started = 0;
3995 pthread_mutex_lock(&s_startupMutex);
3996
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003997 pthread_attr_t attr;
3998 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003999 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004000
Elliott Hughesfd81e712014-01-06 12:46:02 -08004001 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4002 if (result != 0) {
4003 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004004 goto done;
4005 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004006
4007 while (s_started == 0) {
4008 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4009 }
4010
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004011done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004012 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004013}
4014
4015// Used for testing purpose only.
4016extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4017 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4018}
4019
Etan Cohend3652192014-06-20 08:28:44 -07004020static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4021 int fdListen = -1;
4022 int ret;
4023 char socket_name[10];
4024
4025 memset(socket_name, 0, sizeof(char)*10);
4026
4027 switch(socket_id) {
4028 case RIL_SOCKET_1:
4029 strncpy(socket_name, RIL_getRilSocketName(), 9);
4030 break;
4031 #if (SIM_COUNT >= 2)
4032 case RIL_SOCKET_2:
4033 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4034 break;
4035 #endif
4036 #if (SIM_COUNT >= 3)
4037 case RIL_SOCKET_3:
4038 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4039 break;
4040 #endif
4041 #if (SIM_COUNT >= 4)
4042 case RIL_SOCKET_4:
4043 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4044 break;
4045 #endif
4046 default:
4047 RLOGE("Socket id is wrong!!");
4048 return;
4049 }
4050
4051 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4052
4053 fdListen = android_get_control_socket(socket_name);
4054 if (fdListen < 0) {
4055 RLOGE("Failed to get socket %s", socket_name);
4056 exit(-1);
4057 }
4058
4059 ret = listen(fdListen, 4);
4060
4061 if (ret < 0) {
4062 RLOGE("Failed to listen on control socket '%d': %s",
4063 fdListen, strerror(errno));
4064 exit(-1);
4065 }
4066 socket_listen_p->fdListen = fdListen;
4067
4068 /* note: non-persistent so we can accept only one connection at a time */
4069 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4070 listenCallback, socket_listen_p);
4071
4072 rilEventAddWakeup (socket_listen_p->listen_event);
4073}
4074
Wink Saville7f856802009-06-09 10:23:37 -07004075extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004076RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004077 int ret;
4078 int flags;
4079
Etan Cohend3652192014-06-20 08:28:44 -07004080 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4081
Wink Saville43808972011-01-13 17:39:51 -08004082 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004083 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004084 return;
4085 }
Wink Saville43808972011-01-13 17:39:51 -08004086 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004087 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004088 callbacks->version, RIL_VERSION_MIN);
4089 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004090 }
Wink Saville43808972011-01-13 17:39:51 -08004091 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004092 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004093 callbacks->version, RIL_VERSION);
4094 return;
4095 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004096 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004097
4098 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004099 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004100 "Subsequent call ignored");
4101 return;
4102 }
4103
4104 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4105
Etan Cohend3652192014-06-20 08:28:44 -07004106 /* Initialize socket1 parameters */
4107 s_ril_param_socket = {
4108 RIL_SOCKET_1, /* socket_id */
4109 -1, /* fdListen */
4110 -1, /* fdCommand */
4111 PHONE_PROCESS, /* processName */
4112 &s_commands_event, /* commands_event */
4113 &s_listen_event, /* listen_event */
4114 processCommandsCallback, /* processCommandsCallback */
4115 NULL /* p_rs */
4116 };
4117
4118#if (SIM_COUNT >= 2)
4119 s_ril_param_socket2 = {
4120 RIL_SOCKET_2, /* socket_id */
4121 -1, /* fdListen */
4122 -1, /* fdCommand */
4123 PHONE_PROCESS, /* processName */
4124 &s_commands_event_socket2, /* commands_event */
4125 &s_listen_event_socket2, /* listen_event */
4126 processCommandsCallback, /* processCommandsCallback */
4127 NULL /* p_rs */
4128 };
4129#endif
4130
4131#if (SIM_COUNT >= 3)
4132 s_ril_param_socket3 = {
4133 RIL_SOCKET_3, /* socket_id */
4134 -1, /* fdListen */
4135 -1, /* fdCommand */
4136 PHONE_PROCESS, /* processName */
4137 &s_commands_event_socket3, /* commands_event */
4138 &s_listen_event_socket3, /* listen_event */
4139 processCommandsCallback, /* processCommandsCallback */
4140 NULL /* p_rs */
4141 };
4142#endif
4143
4144#if (SIM_COUNT >= 4)
4145 s_ril_param_socket4 = {
4146 RIL_SOCKET_4, /* socket_id */
4147 -1, /* fdListen */
4148 -1, /* fdCommand */
4149 PHONE_PROCESS, /* processName */
4150 &s_commands_event_socket4, /* commands_event */
4151 &s_listen_event_socket4, /* listen_event */
4152 processCommandsCallback, /* processCommandsCallback */
4153 NULL /* p_rs */
4154 };
4155#endif
4156
4157
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004158 s_registerCalled = 1;
4159
Etan Cohend3652192014-06-20 08:28:44 -07004160 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004161 // Little self-check
4162
Wink Savillef4c4d362009-04-02 01:37:03 -07004163 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004164 assert(i == s_commands[i].requestNumber);
4165 }
4166
Wink Savillef4c4d362009-04-02 01:37:03 -07004167 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004168 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004169 == s_unsolResponses[i].requestNumber);
4170 }
4171
4172 // New rild impl calls RIL_startEventLoop() first
4173 // old standalone impl wants it here.
4174
4175 if (s_started == 0) {
4176 RIL_startEventLoop();
4177 }
4178
Etan Cohend3652192014-06-20 08:28:44 -07004179 // start listen socket1
4180 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004181
Etan Cohend3652192014-06-20 08:28:44 -07004182#if (SIM_COUNT >= 2)
4183 // start listen socket2
4184 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4185#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004186
Etan Cohend3652192014-06-20 08:28:44 -07004187#if (SIM_COUNT >= 3)
4188 // start listen socket3
4189 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4190#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004191
Etan Cohend3652192014-06-20 08:28:44 -07004192#if (SIM_COUNT >= 4)
4193 // start listen socket4
4194 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4195#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004196
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004197
4198#if 1
4199 // start debug interface socket
4200
Etan Cohend3652192014-06-20 08:28:44 -07004201 char *inst = NULL;
4202 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4203 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4204 }
4205
4206 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4207 if (inst != NULL) {
4208 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
4209 }
4210
4211 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004212 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004213 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004214 exit(-1);
4215 }
4216
4217 ret = listen(s_fdDebug, 4);
4218
4219 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004220 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004221 s_fdDebug, strerror(errno));
4222 exit(-1);
4223 }
4224
4225 ril_event_set (&s_debug_event, s_fdDebug, true,
4226 debugCallback, NULL);
4227
4228 rilEventAddWakeup (&s_debug_event);
4229#endif
4230
4231}
4232
4233static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004234checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004235 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004236 /* Hook for current context
4237 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4238 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4239 /* pendingRequestsHook refer to &s_pendingRequests */
4240 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004241
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004242 if (pRI == NULL) {
4243 return 0;
4244 }
4245
Etan Cohend3652192014-06-20 08:28:44 -07004246#if (SIM_COUNT >= 2)
4247 if (pRI->socket_id == RIL_SOCKET_2) {
4248 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4249 pendingRequestsHook = &s_pendingRequests_socket2;
4250 }
4251#if (SIM_COUNT >= 3)
4252 if (pRI->socket_id == RIL_SOCKET_3) {
4253 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4254 pendingRequestsHook = &s_pendingRequests_socket3;
4255 }
4256#endif
4257#if (SIM_COUNT >= 4)
4258 if (pRI->socket_id == RIL_SOCKET_4) {
4259 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4260 pendingRequestsHook = &s_pendingRequests_socket4;
4261 }
4262#endif
4263#endif
4264 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004265
Etan Cohend3652192014-06-20 08:28:44 -07004266 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004267 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004268 ; ppCur = &((*ppCur)->p_next)
4269 ) {
4270 if (pRI == *ppCur) {
4271 ret = 1;
4272
4273 *ppCur = (*ppCur)->p_next;
4274 break;
4275 }
4276 }
4277
Etan Cohend3652192014-06-20 08:28:44 -07004278 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004279
4280 return ret;
4281}
4282
4283
4284extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004285RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004286 RequestInfo *pRI;
4287 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004288 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004289 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004290 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004291
4292 pRI = (RequestInfo *)t;
4293
Jayachandran C6c607592014-08-04 15:48:01 -07004294 if (!checkAndDequeueRequestInfo(pRI)) {
4295 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4296 return;
4297 }
4298
Etan Cohend3652192014-06-20 08:28:44 -07004299 socket_id = pRI->socket_id;
4300#if (SIM_COUNT >= 2)
4301 if (socket_id == RIL_SOCKET_2) {
4302 fd = s_ril_param_socket2.fdCommand;
4303 }
4304#if (SIM_COUNT >= 3)
4305 if (socket_id == RIL_SOCKET_3) {
4306 fd = s_ril_param_socket3.fdCommand;
4307 }
4308#endif
4309#if (SIM_COUNT >= 4)
4310 if (socket_id == RIL_SOCKET_4) {
4311 fd = s_ril_param_socket4.fdCommand;
4312 }
4313#endif
4314#endif
4315 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
4316
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004317 if (pRI->local > 0) {
4318 // Locally issued command...void only!
4319 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004320 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004321
4322 goto done;
4323 }
4324
4325 appendPrintBuf("[%04d]< %s",
4326 pRI->token, requestToString(pRI->pCI->requestNumber));
4327
4328 if (pRI->cancelled == 0) {
4329 Parcel p;
4330
4331 p.writeInt32 (RESPONSE_SOLICITED);
4332 p.writeInt32 (pRI->token);
4333 errorOffset = p.dataPosition();
4334
4335 p.writeInt32 (e);
4336
johnwangb2a61842009-06-02 14:55:45 -07004337 if (response != NULL) {
4338 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004339 ret = pRI->pCI->responseFunction(p, response, responselen);
4340
4341 /* if an error occurred, rewind and mark it */
4342 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004343 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004344 p.setDataPosition(errorOffset);
4345 p.writeInt32 (ret);
4346 }
johnwangb2a61842009-06-02 14:55:45 -07004347 }
4348
4349 if (e != RIL_E_SUCCESS) {
4350 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004351 }
4352
Etan Cohend3652192014-06-20 08:28:44 -07004353 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004354 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004355 }
Etan Cohend3652192014-06-20 08:28:44 -07004356 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004357 }
4358
4359done:
4360 free(pRI);
4361}
4362
4363
4364static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004365grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004366 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4367}
4368
4369static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004370releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004371 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4372}
4373
4374/**
4375 * Timer callback to put us back to sleep before the default timeout
4376 */
4377static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004378wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004379 // We're using "param != NULL" as a cancellation mechanism
4380 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004381 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004382
4383 releaseWakeLock();
4384 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004385 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004386 }
4387}
4388
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004389static int
4390decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4391 switch (radioState) {
4392 case RADIO_STATE_SIM_NOT_READY:
4393 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4394 case RADIO_STATE_SIM_READY:
4395 return RADIO_TECH_UMTS;
4396
4397 case RADIO_STATE_RUIM_NOT_READY:
4398 case RADIO_STATE_RUIM_READY:
4399 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4400 case RADIO_STATE_NV_NOT_READY:
4401 case RADIO_STATE_NV_READY:
4402 return RADIO_TECH_1xRTT;
4403
4404 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004405 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004406 return -1;
4407 }
4408}
4409
4410static int
4411decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4412 switch (radioState) {
4413 case RADIO_STATE_SIM_NOT_READY:
4414 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4415 case RADIO_STATE_SIM_READY:
4416 case RADIO_STATE_RUIM_NOT_READY:
4417 case RADIO_STATE_RUIM_READY:
4418 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4419 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4420
4421 case RADIO_STATE_NV_NOT_READY:
4422 case RADIO_STATE_NV_READY:
4423 return CDMA_SUBSCRIPTION_SOURCE_NV;
4424
4425 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004426 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004427 return -1;
4428 }
4429}
4430
4431static int
4432decodeSimStatus (RIL_RadioState radioState) {
4433 switch (radioState) {
4434 case RADIO_STATE_SIM_NOT_READY:
4435 case RADIO_STATE_RUIM_NOT_READY:
4436 case RADIO_STATE_NV_NOT_READY:
4437 case RADIO_STATE_NV_READY:
4438 return -1;
4439 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4440 case RADIO_STATE_SIM_READY:
4441 case RADIO_STATE_RUIM_READY:
4442 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4443 return radioState;
4444 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004445 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004446 return -1;
4447 }
4448}
4449
4450static bool is3gpp2(int radioTech) {
4451 switch (radioTech) {
4452 case RADIO_TECH_IS95A:
4453 case RADIO_TECH_IS95B:
4454 case RADIO_TECH_1xRTT:
4455 case RADIO_TECH_EVDO_0:
4456 case RADIO_TECH_EVDO_A:
4457 case RADIO_TECH_EVDO_B:
4458 case RADIO_TECH_EHRPD:
4459 return true;
4460 default:
4461 return false;
4462 }
4463}
4464
4465/* If RIL sends SIM states or RUIM states, store the voice radio
4466 * technology and subscription source information so that they can be
4467 * returned when telephony framework requests them
4468 */
4469static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004470processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004471
4472 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4473 int newVoiceRadioTech;
4474 int newCdmaSubscriptionSource;
4475 int newSimStatus;
4476
4477 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4478 from Radio State and send change notifications if there has been a change */
4479 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4480 if(newVoiceRadioTech != voiceRadioTech) {
4481 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004482 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4483 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004484 }
4485 if(is3gpp2(newVoiceRadioTech)) {
4486 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4487 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4488 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004489 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4490 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004491 }
4492 }
4493 newSimStatus = decodeSimStatus(newRadioState);
4494 if(newSimStatus != simRuimStatus) {
4495 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004496 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004497 }
4498
4499 /* Send RADIO_ON to telephony */
4500 newRadioState = RADIO_STATE_ON;
4501 }
4502
4503 return newRadioState;
4504}
4505
Etan Cohend3652192014-06-20 08:28:44 -07004506
4507#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004508extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004509void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4510 size_t datalen, RIL_SOCKET_ID socket_id)
4511#else
4512extern "C"
4513void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004514 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004515#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004516{
4517 int unsolResponseIndex;
4518 int ret;
4519 int64_t timeReceived = 0;
4520 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004521 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004522 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4523
4524#if defined(ANDROID_MULTI_SIM)
4525 soc_id = socket_id;
4526#endif
4527
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004528
4529 if (s_registerCalled == 0) {
4530 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004531 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004532 return;
4533 }
Wink Saville7f856802009-06-09 10:23:37 -07004534
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004535 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4536
4537 if ((unsolResponseIndex < 0)
4538 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004539 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004540 return;
4541 }
4542
4543 // Grab a wake lock if needed for this reponse,
4544 // as we exit we'll either release it immediately
4545 // or set a timer to release it later.
4546 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4547 case WAKE_PARTIAL:
4548 grabPartialWakeLock();
4549 shouldScheduleTimeout = true;
4550 break;
4551
4552 case DONT_WAKE:
4553 default:
4554 // No wake lock is grabed so don't set timeout
4555 shouldScheduleTimeout = false;
4556 break;
4557 }
4558
4559 // Mark the time this was received, doing this
4560 // after grabing the wakelock incase getting
4561 // the elapsedRealTime might cause us to goto
4562 // sleep.
4563 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4564 timeReceived = elapsedRealtime();
4565 }
4566
4567 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4568
4569 Parcel p;
4570
4571 p.writeInt32 (RESPONSE_UNSOLICITED);
4572 p.writeInt32 (unsolResponse);
4573
4574 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004575 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004576 if (ret != 0) {
4577 // Problem with the response. Don't continue;
4578 goto error_exit;
4579 }
4580
4581 // some things get more payload
4582 switch(unsolResponse) {
4583 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004584 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004585 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004586 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004587 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004588 break;
4589
4590
4591 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4592 // Store the time that this was received so the
4593 // handler of this message can account for
4594 // the time it takes to arrive and process. In
4595 // particular the system has been known to sleep
4596 // before this message can be processed.
4597 p.writeInt64(timeReceived);
4598 break;
4599 }
4600
Etan Cohend3652192014-06-20 08:28:44 -07004601 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4602 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004603 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4604
4605 // Unfortunately, NITZ time is not poll/update like everything
4606 // else in the system. So, if the upstream client isn't connected,
4607 // keep a copy of the last NITZ response (with receive time noted
4608 // above) around so we can deliver it when it is connected
4609
4610 if (s_lastNITZTimeData != NULL) {
4611 free (s_lastNITZTimeData);
4612 s_lastNITZTimeData = NULL;
4613 }
4614
4615 s_lastNITZTimeData = malloc(p.dataSize());
4616 s_lastNITZTimeDataSize = p.dataSize();
4617 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4618 }
4619
4620 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4621 // FIXME The java code should handshake here to release wake lock
4622
4623 if (shouldScheduleTimeout) {
4624 // Cancel the previous request
4625 if (s_last_wake_timeout_info != NULL) {
4626 s_last_wake_timeout_info->userParam = (void *)1;
4627 }
4628
4629 s_last_wake_timeout_info
4630 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4631 &TIMEVAL_WAKE_TIMEOUT);
4632 }
4633
4634 // Normal exit
4635 return;
4636
4637error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004638 if (shouldScheduleTimeout) {
4639 releaseWakeLock();
4640 }
4641}
4642
Wink Saville7f856802009-06-09 10:23:37 -07004643/** FIXME generalize this if you track UserCAllbackInfo, clear it
4644 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004645*/
4646static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004647internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004648 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004649{
4650 struct timeval myRelativeTime;
4651 UserCallbackInfo *p_info;
4652
4653 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4654
Wink Saville7f856802009-06-09 10:23:37 -07004655 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004656 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004657
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004658 if (relativeTime == NULL) {
4659 /* treat null parameter as a 0 relative time */
4660 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4661 } else {
4662 /* FIXME I think event_add's tv param is really const anyway */
4663 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4664 }
4665
4666 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4667
4668 ril_timer_add(&(p_info->event), &myRelativeTime);
4669
4670 triggerEvLoop();
4671 return p_info;
4672}
4673
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004674
4675extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004676RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4677 const struct timeval *relativeTime) {
4678 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004679}
4680
4681const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004682failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004683 switch(e) {
4684 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004685 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004686 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4687 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4688 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4689 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4690 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4691 case RIL_E_CANCELLED: return "E_CANCELLED";
4692 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4693 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4694 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004695 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004696 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004697#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004698 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4699 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4700#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004701 default: return "<unknown error>";
4702 }
4703}
4704
4705const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004706radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004707 switch(s) {
4708 case RADIO_STATE_OFF: return "RADIO_OFF";
4709 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4710 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4711 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4712 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004713 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4714 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4715 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4716 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4717 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004718 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004719 default: return "<unknown state>";
4720 }
4721}
4722
4723const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004724callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004725 switch(s) {
4726 case RIL_CALL_ACTIVE : return "ACTIVE";
4727 case RIL_CALL_HOLDING: return "HOLDING";
4728 case RIL_CALL_DIALING: return "DIALING";
4729 case RIL_CALL_ALERTING: return "ALERTING";
4730 case RIL_CALL_INCOMING: return "INCOMING";
4731 case RIL_CALL_WAITING: return "WAITING";
4732 default: return "<unknown state>";
4733 }
4734}
4735
4736const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004737requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004738/*
4739 cat libs/telephony/ril_commands.h \
4740 | egrep "^ *{RIL_" \
4741 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4742
4743
4744 cat libs/telephony/ril_unsol_commands.h \
4745 | egrep "^ *{RIL_" \
4746 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4747
4748*/
4749 switch(request) {
4750 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4751 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4752 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4753 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4754 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4755 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4756 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4757 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4758 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4759 case RIL_REQUEST_DIAL: return "DIAL";
4760 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4761 case RIL_REQUEST_HANGUP: return "HANGUP";
4762 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4763 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4764 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4765 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4766 case RIL_REQUEST_UDUB: return "UDUB";
4767 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4768 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004769 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4770 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004771 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4772 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4773 case RIL_REQUEST_DTMF: return "DTMF";
4774 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4775 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004776 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004777 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4778 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4779 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4780 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4781 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4782 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4783 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4784 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4785 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4786 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4787 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4788 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4789 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004790 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004791 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4792 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4793 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4794 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4795 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4796 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4797 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4798 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4799 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4800 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4801 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4802 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4803 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4804 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4805 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4806 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4807 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004808 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4809 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004810 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4811 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4812 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004813 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4814 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004815 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4816 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4817 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4818 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4819 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4820 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4821 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4822 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004823 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004824 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4825 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4826 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4827 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4828 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4829 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4830 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4831 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4832 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4833 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004834 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4835 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4836 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4837 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4838 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004839 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004840 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4841 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4842 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4843 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004844 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4845 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4846 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004847 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004848 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004849 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004850 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004851 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4852 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004853 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004854 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4855 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004856 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004857 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4858 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004859 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4860 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4861 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4862 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004863 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
4864 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Etan Cohend3652192014-06-20 08:28:44 -07004865 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4866 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07004867 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
4868 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07004869 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
4870 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00004871 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004872 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4873 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004874 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 -08004875 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4876 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4877 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4878 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4879 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4880 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4881 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4882 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4883 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4884 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4885 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4886 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4887 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004888 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004889 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004890 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4891 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4892 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4893 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004894 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4895 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4896 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4897 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4898 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004899 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004900 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004901 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004902 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004903 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4904 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004905 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004906 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004907 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004908 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004909 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4910 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4911 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07004912 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07004913 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07004914 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004915 default: return "<unknown request>";
4916 }
4917}
4918
Etan Cohend3652192014-06-20 08:28:44 -07004919const char *
4920rilSocketIdToString(RIL_SOCKET_ID socket_id)
4921{
4922 switch(socket_id) {
4923 case RIL_SOCKET_1:
4924 return "RIL_SOCKET_1";
4925#if (SIM_COUNT >= 2)
4926 case RIL_SOCKET_2:
4927 return "RIL_SOCKET_2";
4928#endif
4929#if (SIM_COUNT >= 3)
4930 case RIL_SOCKET_3:
4931 return "RIL_SOCKET_3";
4932#endif
4933#if (SIM_COUNT >= 4)
4934 case RIL_SOCKET_4:
4935 return "RIL_SOCKET_4";
4936#endif
4937 default:
4938 return "not a valid RIL";
4939 }
4940}
4941
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004942} /* namespace android */