blob: ad59088d59ef8cd44d5280101a615953e23a84e0 [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>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080021#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070022#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080023#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070025#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070029#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080030#include <cutils/jstring.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070032#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080033#include <pwd.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080034#include <stdio.h>
35#include <stdlib.h>
36#include <stdarg.h>
37#include <string.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <time.h>
41#include <errno.h>
42#include <assert.h>
43#include <ctype.h>
44#include <alloca.h>
45#include <sys/un.h>
46#include <assert.h>
47#include <netinet/in.h>
48#include <cutils/properties.h>
Dheeraj Shetty27976c42014-07-02 21:27:57 +020049#include <RilSapSocket.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080050
Dheeraj Shetty27976c42014-07-02 21:27:57 +020051extern "C" void
52RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080053namespace android {
54
55#define PHONE_PROCESS "radio"
Dheeraj Shetty27976c42014-07-02 21:27:57 +020056#define BLUETOOTH_PROCESS "bluetooth"
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080057
58#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070059#define SOCKET2_NAME_RIL "rild2"
60#define SOCKET3_NAME_RIL "rild3"
61#define SOCKET4_NAME_RIL "rild4"
62
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080063#define SOCKET_NAME_RIL_DEBUG "rild-debug"
64
65#define ANDROID_WAKE_LOCK_NAME "radio-interface"
66
Nathan Harolda0153392015-07-28 14:54:58 -070067#define ANDROID_WAKE_LOCK_SECS 0
68#define ANDROID_WAKE_LOCK_USECS 200000
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080069
70#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
71
72// match with constant in RIL.java
73#define MAX_COMMAND_BYTES (8 * 1024)
74
75// Basically: memset buffers that the client library
76// shouldn't be using anymore in an attempt to find
77// memory usage issues sooner.
78#define MEMSET_FREED 1
79
80#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
81
Wink Savillef4c4d362009-04-02 01:37:03 -070082#define MIN(a,b) ((a)<(b) ? (a) : (b))
83
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080084/* Constants for response types */
85#define RESPONSE_SOLICITED 0
86#define RESPONSE_UNSOLICITED 1
87
88/* Negative values for private RIL errno's */
89#define RIL_ERRNO_INVALID_RESPONSE -1
90
91// request, response, and unsolicited msg print macro
92#define PRINTBUF_SIZE 8096
93
Robert Greenwalt191e4dc2015-04-29 16:57:39 -070094// Enable verbose logging
95#define VDBG 0
96
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080097// Enable RILC log
98#define RILC_LOG 0
99
100#if RILC_LOG
101 #define startRequest sprintf(printBuf, "(")
102 #define closeRequest sprintf(printBuf, "%s)", printBuf)
103 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define startResponse sprintf(printBuf, "%s {", printBuf)
107 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800108 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800109
110 #define clearPrintBuf printBuf[0] = 0
111 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
Prasath Balakrishnanf8a27942015-08-05 14:53:50 +0530112 #define appendPrintBuf(x...) snprintf(printBuf, PRINTBUF_SIZE, x)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800113#else
114 #define startRequest
115 #define closeRequest
116 #define printRequest(token, req)
117 #define startResponse
118 #define closeResponse
119 #define printResponse
120 #define clearPrintBuf
121 #define removeLastChar
122 #define appendPrintBuf(x...)
123#endif
124
125enum WakeType {DONT_WAKE, WAKE_PARTIAL};
126
127typedef struct {
128 int requestNumber;
129 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
130 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
131} CommandInfo;
132
133typedef struct {
134 int requestNumber;
135 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
136 WakeType wakeType;
137} UnsolResponseInfo;
138
139typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700140 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800141 CommandInfo *pCI;
142 struct RequestInfo *p_next;
143 char cancelled;
144 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700145 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800146} RequestInfo;
147
Wink Saville3d54e742009-05-18 18:00:44 -0700148typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800149 RIL_TimedCallback p_callback;
150 void *userParam;
151 struct ril_event event;
152 struct UserCallbackInfo *p_next;
153} UserCallbackInfo;
154
Etan Cohend3652192014-06-20 08:28:44 -0700155extern "C" const char * requestToString(int request);
156extern "C" const char * failCauseToString(RIL_Errno);
157extern "C" const char * callStateToString(RIL_CallState);
158extern "C" const char * radioStateToString(RIL_RadioState);
159extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
160
161extern "C"
162char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800163/*******************************************************************/
164
165RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
166static int s_registerCalled = 0;
167
168static pthread_t s_tid_dispatch;
169static pthread_t s_tid_reader;
170static int s_started = 0;
171
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800172static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700173static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800174
175static int s_fdWakeupRead;
176static int s_fdWakeupWrite;
177
178static struct ril_event s_commands_event;
179static struct ril_event s_wakeupfd_event;
180static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700181static SocketListenParam s_ril_param_socket;
182
183static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
184static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
185static RequestInfo *s_pendingRequests = NULL;
186
187#if (SIM_COUNT >= 2)
188static struct ril_event s_commands_event_socket2;
189static struct ril_event s_listen_event_socket2;
190static SocketListenParam s_ril_param_socket2;
191
192static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
193static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
194static RequestInfo *s_pendingRequests_socket2 = NULL;
195#endif
196
197#if (SIM_COUNT >= 3)
198static struct ril_event s_commands_event_socket3;
199static struct ril_event s_listen_event_socket3;
200static SocketListenParam s_ril_param_socket3;
201
202static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
203static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
204static RequestInfo *s_pendingRequests_socket3 = NULL;
205#endif
206
207#if (SIM_COUNT >= 4)
208static struct ril_event s_commands_event_socket4;
209static struct ril_event s_listen_event_socket4;
210static SocketListenParam s_ril_param_socket4;
211
212static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
213static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
214static RequestInfo *s_pendingRequests_socket4 = NULL;
215#endif
216
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800217static struct ril_event s_wake_timeout_event;
218static struct ril_event s_debug_event;
219
220
Nathan Harolda0153392015-07-28 14:54:58 -0700221static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800222
Etan Cohend3652192014-06-20 08:28:44 -0700223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
225static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
226
227static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
228static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
229
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800230static RequestInfo *s_toDispatchHead = NULL;
231static RequestInfo *s_toDispatchTail = NULL;
232
233static UserCallbackInfo *s_last_wake_timeout_info = NULL;
234
235static void *s_lastNITZTimeData = NULL;
236static size_t s_lastNITZTimeDataSize;
237
238#if RILC_LOG
239 static char printBuf[PRINTBUF_SIZE];
240#endif
241
242/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700243static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800244
245static void dispatchVoid (Parcel& p, RequestInfo *pRI);
246static void dispatchString (Parcel& p, RequestInfo *pRI);
247static void dispatchStrings (Parcel& p, RequestInfo *pRI);
248static void dispatchInts (Parcel& p, RequestInfo *pRI);
249static void dispatchDial (Parcel& p, RequestInfo *pRI);
250static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800251static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800252static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
253static void dispatchRaw(Parcel& p, RequestInfo *pRI);
254static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700255static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800256static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700257static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800258static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259
Wink Savillef4c4d362009-04-02 01:37:03 -0700260static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700261static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
262static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
263static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700264static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700265static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700266static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
267static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800268static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
269static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700270static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700271static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000272static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700273static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800274static int responseInts(Parcel &p, void *response, size_t responselen);
Chao Liu548a81e2015-05-14 16:13:46 -0700275static int responseFailCause(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800276static int responseStrings(Parcel &p, void *response, size_t responselen);
277static int responseString(Parcel &p, void *response, size_t responselen);
278static int responseVoid(Parcel &p, void *response, size_t responselen);
279static int responseCallList(Parcel &p, void *response, size_t responselen);
280static int responseSMS(Parcel &p, void *response, size_t responselen);
281static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
282static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700283static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800284static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800285static int responseRaw(Parcel &p, void *response, size_t responselen);
286static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700287static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700288static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
289static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700290static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800291static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700292static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
293static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
294static int responseCallRing(Parcel &p, void *response, size_t responselen);
295static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
296static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800297static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700298static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700299static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700300static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700301static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000302static int responseSSData(Parcel &p, void *response, size_t responselen);
fengluf7408292015-04-14 14:53:55 -0700303static int responseLceStatus(Parcel &p, void *response, size_t responselen);
304static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham73157492015-05-28 00:37:32 -0700305static int responseActivityData(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000306
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800307static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
308static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
309static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
310
Amit Mahajan54563d32014-11-22 00:54:49 +0000311static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
312
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800313#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700314#if defined(ANDROID_MULTI_SIM)
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700315extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -0700316 size_t datalen, RIL_SOCKET_ID socket_id);
317#else
Vinit Deshpande1b1ec2d2015-04-15 13:31:05 -0700318extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800319 size_t datalen);
320#endif
Etan Cohend3652192014-06-20 08:28:44 -0700321#endif
322
323#if defined(ANDROID_MULTI_SIM)
324#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
325#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
326#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
327#else
328#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
329#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
330#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
331#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800332
Wink Saville7f856802009-06-09 10:23:37 -0700333static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700334 (RIL_TimedCallback callback, void *param,
335 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800336
337/** Index == requestNumber */
338static CommandInfo s_commands[] = {
339#include "ril_commands.h"
340};
341
342static UnsolResponseInfo s_unsolResponses[] = {
343#include "ril_unsol_commands.h"
344};
345
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800346/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
347 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
348 radio state message and store it. Every time there is a change in Radio State
349 check to see if voice radio tech changes and notify telephony
350 */
351int voiceRadioTech = -1;
352
353/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
354 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
355 source from radio state and store it. Every time there is a change in Radio State
356 check to see if subscription source changed and notify telephony
357 */
358int cdmaSubscriptionSource = -1;
359
360/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
361 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
362 check to see if SIM/RUIM status changed and notify telephony
363 */
364int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800365
Etan Cohend3652192014-06-20 08:28:44 -0700366static char * RIL_getRilSocketName() {
367 return rild;
368}
369
370extern "C"
Dheeraj Shetty27976c42014-07-02 21:27:57 +0200371void RIL_setRilSocketName(const char * s) {
Etan Cohend3652192014-06-20 08:28:44 -0700372 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
373}
374
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800375static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700376strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800377 size_t stringlen;
378 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700379
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700381
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800382 return strndup16to8(s16, stringlen);
383}
384
Wink Saville8b4e4f72014-10-17 15:01:45 -0700385static status_t
386readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
387 size_t s16Len;
388 const char16_t *s16;
389
390 s16 = p.readString16Inplace(&s16Len);
391 if (s16 == NULL) {
392 return NO_MEMORY;
393 }
394 size_t strLen = strnlen16to8(s16, s16Len);
395 if ((strLen + 1) > maxLen) {
396 return NO_MEMORY;
397 }
398 if (strncpy16to8(str, s16, strLen) == NULL) {
399 return NO_MEMORY;
400 } else {
401 return NO_ERROR;
402 }
403}
404
Wink Savillef4c4d362009-04-02 01:37:03 -0700405static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800406 char16_t *s16;
407 size_t s16_len;
408 s16 = strdup8to16(s, &s16_len);
409 p.writeString16(s16, s16_len);
410 free(s16);
411}
412
413
414static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700415memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800416 if (s != NULL) {
417 memset (s, 0, strlen(s));
418 }
419}
420
421void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
422 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700423 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800424 // do nothing -- the data reference lives longer than the Parcel object
425}
426
Wink Saville7f856802009-06-09 10:23:37 -0700427/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800428 * To be called from dispatch thread
429 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700430 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 */
432static void
Etan Cohend3652192014-06-20 08:28:44 -0700433issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800434 RequestInfo *pRI;
435 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700436 /* Hook for current context */
437 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
438 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
439 /* pendingRequestsHook refer to &s_pendingRequests */
440 RequestInfo** pendingRequestsHook = &s_pendingRequests;
441
442#if (SIM_COUNT == 2)
443 if (socket_id == RIL_SOCKET_2) {
444 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
445 pendingRequestsHook = &s_pendingRequests_socket2;
446 }
447#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800448
449 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
450
451 pRI->local = 1;
452 pRI->token = 0xffffffff; // token is not used in this context
453 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700454 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800455
Etan Cohend3652192014-06-20 08:28:44 -0700456 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800457 assert (ret == 0);
458
Etan Cohend3652192014-06-20 08:28:44 -0700459 pRI->p_next = *pendingRequestsHook;
460 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800461
Etan Cohend3652192014-06-20 08:28:44 -0700462 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800463 assert (ret == 0);
464
Wink Saville8eb2a122012-11-19 16:05:13 -0800465 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800466
Etan Cohend3652192014-06-20 08:28:44 -0700467 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800468}
469
470
471
472static int
Etan Cohend3652192014-06-20 08:28:44 -0700473processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800474 Parcel p;
475 status_t status;
476 int32_t request;
477 int32_t token;
478 RequestInfo *pRI;
479 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700480 /* Hook for current context */
481 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
482 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
483 /* pendingRequestsHook refer to &s_pendingRequests */
484 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800485
486 p.setData((uint8_t *) buffer, buflen);
487
488 // status checked at end
489 status = p.readInt32(&request);
490 status = p.readInt32 (&token);
491
Etan Cohend3652192014-06-20 08:28:44 -0700492#if (SIM_COUNT >= 2)
493 if (socket_id == RIL_SOCKET_2) {
494 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
495 pendingRequestsHook = &s_pendingRequests_socket2;
496 }
497#if (SIM_COUNT >= 3)
498 else if (socket_id == RIL_SOCKET_3) {
499 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
500 pendingRequestsHook = &s_pendingRequests_socket3;
501 }
502#endif
503#if (SIM_COUNT >= 4)
504 else if (socket_id == RIL_SOCKET_4) {
505 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
506 pendingRequestsHook = &s_pendingRequests_socket4;
507 }
508#endif
509#endif
510
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800511 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800512 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800513 return 0;
514 }
515
516 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700517 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800518 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800519 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700520 pErr.writeInt32 (RESPONSE_SOLICITED);
521 pErr.writeInt32 (token);
522 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
523
524 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800525 return 0;
526 }
527
528
529 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
530
531 pRI->token = token;
532 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700533 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800534
Etan Cohend3652192014-06-20 08:28:44 -0700535 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800536 assert (ret == 0);
537
Etan Cohend3652192014-06-20 08:28:44 -0700538 pRI->p_next = *pendingRequestsHook;
539 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540
Etan Cohend3652192014-06-20 08:28:44 -0700541 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800542 assert (ret == 0);
543
544/* sLastDispatchedToken = token; */
545
Wink Saville7f856802009-06-09 10:23:37 -0700546 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547
548 return 0;
549}
550
551static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700552invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800553 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800554 pRI->token, requestToString(pRI->pCI->requestNumber));
555}
556
557/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700558static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700559dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800560 clearPrintBuf;
561 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700562 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800563}
564
565/** Callee expects const char * */
566static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700567dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800568 status_t status;
569 size_t datalen;
570 size_t stringlen;
571 char *string8 = NULL;
572
573 string8 = strdupReadString(p);
574
575 startRequest;
576 appendPrintBuf("%s%s", printBuf, string8);
577 closeRequest;
578 printRequest(pRI->token, pRI->pCI->requestNumber);
579
Etan Cohend3652192014-06-20 08:28:44 -0700580 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
581 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800582
583#ifdef MEMSET_FREED
584 memsetString(string8);
585#endif
586
587 free(string8);
588 return;
589invalid:
590 invalidCommandBlock(pRI);
591 return;
592}
593
594/** Callee expects const char ** */
595static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700596dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800597 int32_t countStrings;
598 status_t status;
599 size_t datalen;
600 char **pStrings;
601
602 status = p.readInt32 (&countStrings);
603
604 if (status != NO_ERROR) {
605 goto invalid;
606 }
607
608 startRequest;
609 if (countStrings == 0) {
610 // just some non-null pointer
611 pStrings = (char **)alloca(sizeof(char *));
612 datalen = 0;
613 } else if (((int)countStrings) == -1) {
614 pStrings = NULL;
615 datalen = 0;
616 } else {
617 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700618
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800619 pStrings = (char **)alloca(datalen);
620
621 for (int i = 0 ; i < countStrings ; i++) {
622 pStrings[i] = strdupReadString(p);
623 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
624 }
625 }
626 removeLastChar;
627 closeRequest;
628 printRequest(pRI->token, pRI->pCI->requestNumber);
629
Etan Cohend3652192014-06-20 08:28:44 -0700630 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800631
632 if (pStrings != NULL) {
633 for (int i = 0 ; i < countStrings ; i++) {
634#ifdef MEMSET_FREED
635 memsetString (pStrings[i]);
636#endif
637 free(pStrings[i]);
638 }
639
640#ifdef MEMSET_FREED
641 memset(pStrings, 0, datalen);
642#endif
643 }
Wink Saville7f856802009-06-09 10:23:37 -0700644
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800645 return;
646invalid:
647 invalidCommandBlock(pRI);
648 return;
649}
650
651/** Callee expects const int * */
652static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700653dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800654 int32_t count;
655 status_t status;
656 size_t datalen;
657 int *pInts;
658
659 status = p.readInt32 (&count);
660
661 if (status != NO_ERROR || count == 0) {
662 goto invalid;
663 }
664
665 datalen = sizeof(int) * count;
666 pInts = (int *)alloca(datalen);
667
668 startRequest;
669 for (int i = 0 ; i < count ; i++) {
670 int32_t t;
671
672 status = p.readInt32(&t);
673 pInts[i] = (int)t;
674 appendPrintBuf("%s%d,", printBuf, t);
675
676 if (status != NO_ERROR) {
677 goto invalid;
678 }
679 }
680 removeLastChar;
681 closeRequest;
682 printRequest(pRI->token, pRI->pCI->requestNumber);
683
Etan Cohend3652192014-06-20 08:28:44 -0700684 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
685 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800686
687#ifdef MEMSET_FREED
688 memset(pInts, 0, datalen);
689#endif
690
691 return;
692invalid:
693 invalidCommandBlock(pRI);
694 return;
695}
696
697
Wink Saville7f856802009-06-09 10:23:37 -0700698/**
699 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800700 * Payload is:
701 * int32_t status
702 * String pdu
703 */
704static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700705dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800706 RIL_SMS_WriteArgs args;
707 int32_t t;
708 status_t status;
709
Mark Salyzyndba25612015-04-09 07:18:35 -0700710 RLOGD("dispatchSmsWrite");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800711 memset (&args, 0, sizeof(args));
712
713 status = p.readInt32(&t);
714 args.status = (int)t;
715
716 args.pdu = strdupReadString(p);
717
718 if (status != NO_ERROR || args.pdu == NULL) {
719 goto invalid;
720 }
721
722 args.smsc = strdupReadString(p);
723
724 startRequest;
725 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
726 (char*)args.pdu, (char*)args.smsc);
727 closeRequest;
728 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700729
Etan Cohend3652192014-06-20 08:28:44 -0700730 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800731
732#ifdef MEMSET_FREED
733 memsetString (args.pdu);
734#endif
735
736 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700737
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800738#ifdef MEMSET_FREED
739 memset(&args, 0, sizeof(args));
740#endif
741
742 return;
743invalid:
744 invalidCommandBlock(pRI);
745 return;
746}
747
Wink Saville7f856802009-06-09 10:23:37 -0700748/**
749 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800750 * Payload is:
751 * String address
752 * int32_t clir
753 */
754static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700755dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800756 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800757 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800758 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800759 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800760 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800761 status_t status;
762
Mark Salyzyndba25612015-04-09 07:18:35 -0700763 RLOGD("dispatchDial");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800764 memset (&dial, 0, sizeof(dial));
765
766 dial.address = strdupReadString(p);
767
768 status = p.readInt32(&t);
769 dial.clir = (int)t;
770
771 if (status != NO_ERROR || dial.address == NULL) {
772 goto invalid;
773 }
774
Wink Saville3a4840b2010-04-07 13:29:58 -0700775 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800776 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800777 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800778 } else {
779 status = p.readInt32(&uusPresent);
780
781 if (status != NO_ERROR) {
782 goto invalid;
783 }
784
785 if (uusPresent == 0) {
786 dial.uusInfo = NULL;
787 } else {
788 int32_t len;
789
790 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
791
792 status = p.readInt32(&t);
793 uusInfo.uusType = (RIL_UUS_Type) t;
794
795 status = p.readInt32(&t);
796 uusInfo.uusDcs = (RIL_UUS_DCS) t;
797
798 status = p.readInt32(&len);
799 if (status != NO_ERROR) {
800 goto invalid;
801 }
802
803 // The java code writes -1 for null arrays
804 if (((int) len) == -1) {
805 uusInfo.uusData = NULL;
806 len = 0;
807 } else {
808 uusInfo.uusData = (char*) p.readInplace(len);
809 }
810
811 uusInfo.uusLength = len;
812 dial.uusInfo = &uusInfo;
813 }
Wink Saville7bce0822010-01-08 15:20:12 -0800814 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800815 }
816
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800817 startRequest;
818 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800819 if (uusPresent) {
820 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
821 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
822 dial.uusInfo->uusLength);
823 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800824 closeRequest;
825 printRequest(pRI->token, pRI->pCI->requestNumber);
826
Etan Cohend3652192014-06-20 08:28:44 -0700827 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800828
829#ifdef MEMSET_FREED
830 memsetString (dial.address);
831#endif
832
833 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700834
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800835#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800836 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800837 memset(&dial, 0, sizeof(dial));
838#endif
839
840 return;
841invalid:
842 invalidCommandBlock(pRI);
843 return;
844}
845
Wink Saville7f856802009-06-09 10:23:37 -0700846/**
847 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800848 * Payload is:
849 * int32_t command
850 * int32_t fileid
851 * String path
852 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700853 * String data
854 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800855 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800856 */
857static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700858dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800859 union RIL_SIM_IO {
860 RIL_SIM_IO_v6 v6;
861 RIL_SIM_IO_v5 v5;
862 } simIO;
863
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800864 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800865 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800866 status_t status;
867
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700868#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700869 RLOGD("dispatchSIM_IO");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700870#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871 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
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700948#if VDBG
Mark Salyzyndba25612015-04-09 07:18:35 -0700949 RLOGD("dispatchSIM_APDU");
Robert Greenwalt191e4dc2015-04-29 16:57:39 -0700950#endif
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800951 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
952
953 // Note we only check status at the end. Any single failure leads to
954 // subsequent reads filing.
955 status = p.readInt32(&t);
956 apdu.sessionid = (int)t;
957
958 status = p.readInt32(&t);
959 apdu.cla = (int)t;
960
961 status = p.readInt32(&t);
962 apdu.instruction = (int)t;
963
964 status = p.readInt32(&t);
965 apdu.p1 = (int)t;
966
967 status = p.readInt32(&t);
968 apdu.p2 = (int)t;
969
970 status = p.readInt32(&t);
971 apdu.p3 = (int)t;
972
973 apdu.data = strdupReadString(p);
974
975 startRequest;
976 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
977 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
978 apdu.p3, (char*)apdu.data);
979 closeRequest;
980 printRequest(pRI->token, pRI->pCI->requestNumber);
981
982 if (status != NO_ERROR) {
983 goto invalid;
984 }
985
Etan Cohend3652192014-06-20 08:28:44 -0700986 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800987
988#ifdef MEMSET_FREED
989 memsetString(apdu.data);
990#endif
991 free(apdu.data);
992
993#ifdef MEMSET_FREED
994 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
995#endif
996
997 return;
998invalid:
999 invalidCommandBlock(pRI);
1000 return;
1001}
1002
1003
1004/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001005 * Callee expects const RIL_CallForwardInfo *
1006 * Payload is:
1007 * int32_t status/action
1008 * int32_t reason
1009 * int32_t serviceCode
1010 * int32_t toa
1011 * String number (0 length -> null)
1012 * int32_t timeSeconds
1013 */
Wink Saville7f856802009-06-09 10:23:37 -07001014static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001015dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001016 RIL_CallForwardInfo cff;
1017 int32_t t;
1018 status_t status;
1019
Mark Salyzyndba25612015-04-09 07:18:35 -07001020 RLOGD("dispatchCallForward");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001021 memset (&cff, 0, sizeof(cff));
1022
Wink Saville7f856802009-06-09 10:23:37 -07001023 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001024
1025 status = p.readInt32(&t);
1026 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001027
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001028 status = p.readInt32(&t);
1029 cff.reason = (int)t;
1030
1031 status = p.readInt32(&t);
1032 cff.serviceClass = (int)t;
1033
1034 status = p.readInt32(&t);
1035 cff.toa = (int)t;
1036
1037 cff.number = strdupReadString(p);
1038
1039 status = p.readInt32(&t);
1040 cff.timeSeconds = (int)t;
1041
1042 if (status != NO_ERROR) {
1043 goto invalid;
1044 }
1045
1046 // special case: number 0-length fields is null
1047
1048 if (cff.number != NULL && strlen (cff.number) == 0) {
1049 cff.number = NULL;
1050 }
1051
1052 startRequest;
1053 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1054 cff.status, cff.reason, cff.serviceClass, cff.toa,
1055 (char*)cff.number, cff.timeSeconds);
1056 closeRequest;
1057 printRequest(pRI->token, pRI->pCI->requestNumber);
1058
Etan Cohend3652192014-06-20 08:28:44 -07001059 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001060
1061#ifdef MEMSET_FREED
1062 memsetString(cff.number);
1063#endif
1064
1065 free (cff.number);
1066
1067#ifdef MEMSET_FREED
1068 memset(&cff, 0, sizeof(cff));
1069#endif
1070
1071 return;
1072invalid:
1073 invalidCommandBlock(pRI);
1074 return;
1075}
1076
1077
Wink Saville7f856802009-06-09 10:23:37 -07001078static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001079dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001080 int32_t len;
1081 status_t status;
1082 const void *data;
1083
1084 status = p.readInt32(&len);
1085
1086 if (status != NO_ERROR) {
1087 goto invalid;
1088 }
1089
1090 // The java code writes -1 for null arrays
1091 if (((int)len) == -1) {
1092 data = NULL;
1093 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001094 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001095
1096 data = p.readInplace(len);
1097
1098 startRequest;
1099 appendPrintBuf("%sraw_size=%d", printBuf, len);
1100 closeRequest;
1101 printRequest(pRI->token, pRI->pCI->requestNumber);
1102
Etan Cohend3652192014-06-20 08:28:44 -07001103 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001104
1105 return;
1106invalid:
1107 invalidCommandBlock(pRI);
1108 return;
1109}
1110
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001111static status_t
1112constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001113 int32_t t;
1114 uint8_t ut;
1115 status_t status;
1116 int32_t digitCount;
1117 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001118
Wink Savillef4c4d362009-04-02 01:37:03 -07001119 memset(&rcsm, 0, sizeof(rcsm));
1120
1121 status = p.readInt32(&t);
1122 rcsm.uTeleserviceID = (int) t;
1123
1124 status = p.read(&ut,sizeof(ut));
1125 rcsm.bIsServicePresent = (uint8_t) ut;
1126
1127 status = p.readInt32(&t);
1128 rcsm.uServicecategory = (int) t;
1129
1130 status = p.readInt32(&t);
1131 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1132
1133 status = p.readInt32(&t);
1134 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1135
1136 status = p.readInt32(&t);
1137 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1138
1139 status = p.readInt32(&t);
1140 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1141
1142 status = p.read(&ut,sizeof(ut));
1143 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1144
1145 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1146 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1147 status = p.read(&ut,sizeof(ut));
1148 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1149 }
1150
Wink Saville7f856802009-06-09 10:23:37 -07001151 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001152 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1153
Wink Saville7f856802009-06-09 10:23:37 -07001154 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001155 rcsm.sSubAddress.odd = (uint8_t) ut;
1156
1157 status = p.read(&ut,sizeof(ut));
1158 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1159
1160 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001161 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1162 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001163 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1164 }
1165
Wink Saville7f856802009-06-09 10:23:37 -07001166 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001167 rcsm.uBearerDataLen = (int) t;
1168
1169 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001170 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1171 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001172 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1173 }
1174
1175 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001176 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001177 }
1178
1179 startRequest;
1180 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001181 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001182 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001183 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001184 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001185
Wink Savillef4c4d362009-04-02 01:37:03 -07001186 printRequest(pRI->token, pRI->pCI->requestNumber);
1187
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001188 return status;
1189}
1190
1191static void
1192dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1193 RIL_CDMA_SMS_Message rcsm;
1194
Mark Salyzyndba25612015-04-09 07:18:35 -07001195 RLOGD("dispatchCdmaSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001196 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1197 goto invalid;
1198 }
1199
Etan Cohend3652192014-06-20 08:28:44 -07001200 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001201
1202#ifdef MEMSET_FREED
1203 memset(&rcsm, 0, sizeof(rcsm));
1204#endif
1205
1206 return;
1207
1208invalid:
1209 invalidCommandBlock(pRI);
1210 return;
1211}
1212
Wink Saville7f856802009-06-09 10:23:37 -07001213static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001214dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1215 RIL_IMS_SMS_Message rism;
1216 RIL_CDMA_SMS_Message rcsm;
1217
Mark Salyzyndba25612015-04-09 07:18:35 -07001218 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001219
1220 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1221 goto invalid;
1222 }
1223 memset(&rism, 0, sizeof(rism));
1224 rism.tech = RADIO_TECH_3GPP2;
1225 rism.retry = retry;
1226 rism.messageRef = messageRef;
1227 rism.message.cdmaMessage = &rcsm;
1228
Etan Cohend3652192014-06-20 08:28:44 -07001229 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001230 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001231 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001232
1233#ifdef MEMSET_FREED
1234 memset(&rcsm, 0, sizeof(rcsm));
1235 memset(&rism, 0, sizeof(rism));
1236#endif
1237
1238 return;
1239
1240invalid:
1241 invalidCommandBlock(pRI);
1242 return;
1243}
1244
1245static void
1246dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1247 RIL_IMS_SMS_Message rism;
1248 int32_t countStrings;
1249 status_t status;
1250 size_t datalen;
1251 char **pStrings;
Mark Salyzyndba25612015-04-09 07:18:35 -07001252 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001253
1254 status = p.readInt32 (&countStrings);
1255
1256 if (status != NO_ERROR) {
1257 goto invalid;
1258 }
1259
1260 memset(&rism, 0, sizeof(rism));
1261 rism.tech = RADIO_TECH_3GPP;
1262 rism.retry = retry;
1263 rism.messageRef = messageRef;
1264
1265 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001266 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1267 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001268 if (countStrings == 0) {
1269 // just some non-null pointer
1270 pStrings = (char **)alloca(sizeof(char *));
1271 datalen = 0;
1272 } else if (((int)countStrings) == -1) {
1273 pStrings = NULL;
1274 datalen = 0;
1275 } else {
1276 datalen = sizeof(char *) * countStrings;
1277
1278 pStrings = (char **)alloca(datalen);
1279
1280 for (int i = 0 ; i < countStrings ; i++) {
1281 pStrings[i] = strdupReadString(p);
1282 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1283 }
1284 }
1285 removeLastChar;
1286 closeRequest;
1287 printRequest(pRI->token, pRI->pCI->requestNumber);
1288
1289 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001290 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001291 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001292 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001293
1294 if (pStrings != NULL) {
1295 for (int i = 0 ; i < countStrings ; i++) {
1296#ifdef MEMSET_FREED
1297 memsetString (pStrings[i]);
1298#endif
1299 free(pStrings[i]);
1300 }
1301
1302#ifdef MEMSET_FREED
1303 memset(pStrings, 0, datalen);
1304#endif
1305 }
1306
1307#ifdef MEMSET_FREED
1308 memset(&rism, 0, sizeof(rism));
1309#endif
1310 return;
1311invalid:
1312 ALOGE("dispatchImsGsmSms invalid block");
1313 invalidCommandBlock(pRI);
1314 return;
1315}
1316
1317static void
1318dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1319 int32_t t;
1320 status_t status = p.readInt32(&t);
1321 RIL_RadioTechnologyFamily format;
1322 uint8_t retry;
1323 int32_t messageRef;
1324
Mark Salyzyndba25612015-04-09 07:18:35 -07001325 RLOGD("dispatchImsSms");
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001326 if (status != NO_ERROR) {
1327 goto invalid;
1328 }
1329 format = (RIL_RadioTechnologyFamily) t;
1330
1331 // read retry field
1332 status = p.read(&retry,sizeof(retry));
1333 if (status != NO_ERROR) {
1334 goto invalid;
1335 }
1336 // read messageRef field
1337 status = p.read(&messageRef,sizeof(messageRef));
1338 if (status != NO_ERROR) {
1339 goto invalid;
1340 }
1341
1342 if (RADIO_TECH_3GPP == format) {
1343 dispatchImsGsmSms(p, pRI, retry, messageRef);
1344 } else if (RADIO_TECH_3GPP2 == format) {
1345 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1346 } else {
1347 ALOGE("requestImsSendSMS invalid format value =%d", format);
1348 }
1349
1350 return;
1351
1352invalid:
1353 invalidCommandBlock(pRI);
1354 return;
1355}
1356
1357static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001358dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1359 RIL_CDMA_SMS_Ack rcsa;
1360 int32_t t;
1361 status_t status;
1362 int32_t digitCount;
1363
Mark Salyzyndba25612015-04-09 07:18:35 -07001364 RLOGD("dispatchCdmaSmsAck");
Wink Savillef4c4d362009-04-02 01:37:03 -07001365 memset(&rcsa, 0, sizeof(rcsa));
1366
1367 status = p.readInt32(&t);
1368 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1369
1370 status = p.readInt32(&t);
1371 rcsa.uSMSCauseCode = (int) t;
1372
1373 if (status != NO_ERROR) {
1374 goto invalid;
1375 }
1376
1377 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001378 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1379 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001380 closeRequest;
1381
1382 printRequest(pRI->token, pRI->pCI->requestNumber);
1383
Etan Cohend3652192014-06-20 08:28:44 -07001384 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001385
1386#ifdef MEMSET_FREED
1387 memset(&rcsa, 0, sizeof(rcsa));
1388#endif
1389
1390 return;
1391
1392invalid:
1393 invalidCommandBlock(pRI);
1394 return;
1395}
1396
Wink Savillea592eeb2009-05-22 13:26:36 -07001397static void
1398dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1399 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001400 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001401 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001402
Wink Savillea592eeb2009-05-22 13:26:36 -07001403 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001404 if (status != NO_ERROR) {
1405 goto invalid;
1406 }
1407
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001408 {
1409 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1410 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001411
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001412 startRequest;
1413 for (int i = 0 ; i < num ; i++ ) {
1414 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001415
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001416 status = p.readInt32(&t);
1417 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001418
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 status = p.readInt32(&t);
1420 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001421
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001422 status = p.readInt32(&t);
1423 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001424
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001425 status = p.readInt32(&t);
1426 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001428 status = p.readInt32(&t);
1429 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001430
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001431 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1432 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1433 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1434 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1435 gsmBci[i].selected);
1436 }
1437 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001438
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001439 if (status != NO_ERROR) {
1440 goto invalid;
1441 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001442
Etan Cohend3652192014-06-20 08:28:44 -07001443 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001444 gsmBciPtrs,
1445 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001446 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001447
1448#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001449 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1450 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001451#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001452 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001453
1454 return;
1455
1456invalid:
1457 invalidCommandBlock(pRI);
1458 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001459}
Wink Savillef4c4d362009-04-02 01:37:03 -07001460
Wink Savillea592eeb2009-05-22 13:26:36 -07001461static void
1462dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1463 int32_t t;
1464 status_t status;
1465 int32_t num;
1466
1467 status = p.readInt32(&num);
1468 if (status != NO_ERROR) {
1469 goto invalid;
1470 }
1471
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001472 {
1473 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1474 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001475
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001476 startRequest;
1477 for (int i = 0 ; i < num ; i++ ) {
1478 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001479
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001480 status = p.readInt32(&t);
1481 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001482
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001483 status = p.readInt32(&t);
1484 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001485
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001486 status = p.readInt32(&t);
1487 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001488
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001489 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1490 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1491 cdmaBci[i].language, cdmaBci[i].selected);
1492 }
1493 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001494
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001495 if (status != NO_ERROR) {
1496 goto invalid;
1497 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
Etan Cohend3652192014-06-20 08:28:44 -07001499 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001500 cdmaBciPtrs,
1501 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001502 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001503
1504#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001505 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1506 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001507#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001508 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001509
1510 return;
1511
1512invalid:
1513 invalidCommandBlock(pRI);
1514 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001515}
1516
1517static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1518 RIL_CDMA_SMS_WriteArgs rcsw;
1519 int32_t t;
1520 uint32_t ut;
1521 uint8_t uct;
1522 status_t status;
1523 int32_t digitCount;
lrichard1021d9a2013-10-29 14:55:30 +08001524 int32_t digitLimit;
Wink Savillef4c4d362009-04-02 01:37:03 -07001525
1526 memset(&rcsw, 0, sizeof(rcsw));
1527
1528 status = p.readInt32(&t);
1529 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001530
Wink Savillef4c4d362009-04-02 01:37:03 -07001531 status = p.readInt32(&t);
1532 rcsw.message.uTeleserviceID = (int) t;
1533
1534 status = p.read(&uct,sizeof(uct));
1535 rcsw.message.bIsServicePresent = (uint8_t) uct;
1536
1537 status = p.readInt32(&t);
1538 rcsw.message.uServicecategory = (int) t;
1539
1540 status = p.readInt32(&t);
1541 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1542
1543 status = p.readInt32(&t);
1544 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1545
1546 status = p.readInt32(&t);
1547 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1548
1549 status = p.readInt32(&t);
1550 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1551
1552 status = p.read(&uct,sizeof(uct));
1553 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1554
lrichard1021d9a2013-10-29 14:55:30 +08001555 digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1556
1557 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001558 status = p.read(&uct,sizeof(uct));
1559 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1560 }
1561
Wink Savillea592eeb2009-05-22 13:26:36 -07001562 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001563 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1564
Wink Savillea592eeb2009-05-22 13:26:36 -07001565 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001566 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1567
1568 status = p.read(&uct,sizeof(uct));
1569 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1570
lrichard1021d9a2013-10-29 14:55:30 +08001571 digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1572
1573 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001574 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001575 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1576 }
1577
Wink Savillea592eeb2009-05-22 13:26:36 -07001578 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001579 rcsw.message.uBearerDataLen = (int) t;
1580
lrichard1021d9a2013-10-29 14:55:30 +08001581 digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1582
1583 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001584 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1586 }
1587
1588 if (status != NO_ERROR) {
1589 goto invalid;
1590 }
1591
1592 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001593 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1594 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1595 message.sAddress.number_mode=%d, \
1596 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001597 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001598 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1599 rcsw.message.sAddress.number_mode,
1600 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001601 closeRequest;
1602
1603 printRequest(pRI->token, pRI->pCI->requestNumber);
1604
Etan Cohend3652192014-06-20 08:28:44 -07001605 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001606
1607#ifdef MEMSET_FREED
1608 memset(&rcsw, 0, sizeof(rcsw));
1609#endif
1610
1611 return;
1612
1613invalid:
1614 invalidCommandBlock(pRI);
1615 return;
1616
1617}
1618
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001619// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1620// Version 4 of the RIL interface adds a new PDP type parameter to support
1621// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1622// RIL, remove the parameter from the request.
1623static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1624 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1625 const int numParamsRilV3 = 6;
1626
1627 // The first bytes of the RIL parcel contain the request number and the
1628 // serial number - see processCommandBuffer(). Copy them over too.
1629 int pos = p.dataPosition();
1630
1631 int numParams = p.readInt32();
1632 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1633 Parcel p2;
1634 p2.appendFrom(&p, 0, pos);
1635 p2.writeInt32(numParamsRilV3);
1636 for(int i = 0; i < numParamsRilV3; i++) {
1637 p2.writeString16(p.readString16());
1638 }
1639 p2.setDataPosition(pos);
1640 dispatchStrings(p2, pRI);
1641 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001642 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001643 dispatchStrings(p, pRI);
1644 }
1645}
1646
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001647// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1648// When all RILs handle this request, this function can be removed and
1649// the request can be sent directly to the RIL using dispatchVoid.
1650static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001651 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001652
Sooraj Sasindrancdfadb62015-10-08 16:03:16 -07001653 if (RADIO_STATE_UNAVAILABLE == state) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001654 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1655 }
1656
Sooraj Sasindrancdfadb62015-10-08 16:03:16 -07001657 // If radio is available then RIL should support this request.
1658 if ((RADIO_STATE_ON == state) || (RADIO_STATE_OFF == state)){
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001659 dispatchVoid(p, pRI);
1660 return;
1661 }
1662
1663 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1664 // will not support this new request either and decode Voice Radio Technology
1665 // from Radio State
1666 voiceRadioTech = decodeVoiceRadioTechnology(state);
1667
1668 if (voiceRadioTech < 0)
1669 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1670 else
1671 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1672}
1673
1674// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1675// When all RILs handle this request, this function can be removed and
1676// the request can be sent directly to the RIL using dispatchVoid.
1677static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001678 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001679
1680 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1681 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1682 }
1683
1684 // RILs that support RADIO_STATE_ON should support this request.
1685 if (RADIO_STATE_ON == state) {
1686 dispatchVoid(p, pRI);
1687 return;
1688 }
1689
1690 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1691 // will not support this new request either and decode CDMA Subscription Source
1692 // from Radio State
1693 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1694
1695 if (cdmaSubscriptionSource < 0)
1696 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1697 else
1698 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1699}
1700
Sungmin Choi75697532013-04-26 15:04:45 -07001701static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1702{
1703 RIL_InitialAttachApn pf;
1704 int32_t t;
1705 status_t status;
1706
1707 memset(&pf, 0, sizeof(pf));
1708
1709 pf.apn = strdupReadString(p);
1710 pf.protocol = strdupReadString(p);
1711
1712 status = p.readInt32(&t);
1713 pf.authtype = (int) t;
1714
1715 pf.username = strdupReadString(p);
1716 pf.password = strdupReadString(p);
1717
1718 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001719 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1720 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001721 closeRequest;
1722 printRequest(pRI->token, pRI->pCI->requestNumber);
1723
1724 if (status != NO_ERROR) {
1725 goto invalid;
1726 }
Etan Cohend3652192014-06-20 08:28:44 -07001727 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001728
1729#ifdef MEMSET_FREED
1730 memsetString(pf.apn);
1731 memsetString(pf.protocol);
1732 memsetString(pf.username);
1733 memsetString(pf.password);
1734#endif
1735
1736 free(pf.apn);
1737 free(pf.protocol);
1738 free(pf.username);
1739 free(pf.password);
1740
1741#ifdef MEMSET_FREED
1742 memset(&pf, 0, sizeof(pf));
1743#endif
1744
1745 return;
1746invalid:
1747 invalidCommandBlock(pRI);
1748 return;
1749}
1750
Jake Hamby8a4a2332014-01-15 13:12:05 -08001751static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1752 RIL_NV_ReadItem nvri;
1753 int32_t t;
1754 status_t status;
1755
1756 memset(&nvri, 0, sizeof(nvri));
1757
1758 status = p.readInt32(&t);
1759 nvri.itemID = (RIL_NV_Item) t;
1760
1761 if (status != NO_ERROR) {
1762 goto invalid;
1763 }
1764
1765 startRequest;
1766 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1767 closeRequest;
1768
1769 printRequest(pRI->token, pRI->pCI->requestNumber);
1770
Etan Cohend3652192014-06-20 08:28:44 -07001771 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001772
1773#ifdef MEMSET_FREED
1774 memset(&nvri, 0, sizeof(nvri));
1775#endif
1776
1777 return;
1778
1779invalid:
1780 invalidCommandBlock(pRI);
1781 return;
1782}
1783
1784static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1785 RIL_NV_WriteItem nvwi;
1786 int32_t t;
1787 status_t status;
1788
1789 memset(&nvwi, 0, sizeof(nvwi));
1790
1791 status = p.readInt32(&t);
1792 nvwi.itemID = (RIL_NV_Item) t;
1793
1794 nvwi.value = strdupReadString(p);
1795
1796 if (status != NO_ERROR || nvwi.value == NULL) {
1797 goto invalid;
1798 }
1799
1800 startRequest;
1801 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1802 nvwi.value);
1803 closeRequest;
1804
1805 printRequest(pRI->token, pRI->pCI->requestNumber);
1806
Etan Cohend3652192014-06-20 08:28:44 -07001807 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001808
1809#ifdef MEMSET_FREED
1810 memsetString(nvwi.value);
1811#endif
1812
1813 free(nvwi.value);
1814
1815#ifdef MEMSET_FREED
1816 memset(&nvwi, 0, sizeof(nvwi));
1817#endif
1818
1819 return;
1820
1821invalid:
1822 invalidCommandBlock(pRI);
1823 return;
1824}
1825
1826
Etan Cohend3652192014-06-20 08:28:44 -07001827static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1828 RIL_SelectUiccSub uicc_sub;
1829 status_t status;
1830 int32_t t;
1831 memset(&uicc_sub, 0, sizeof(uicc_sub));
1832
1833 status = p.readInt32(&t);
1834 if (status != NO_ERROR) {
1835 goto invalid;
1836 }
1837 uicc_sub.slot = (int) t;
1838
1839 status = p.readInt32(&t);
1840 if (status != NO_ERROR) {
1841 goto invalid;
1842 }
1843 uicc_sub.app_index = (int) t;
1844
1845 status = p.readInt32(&t);
1846 if (status != NO_ERROR) {
1847 goto invalid;
1848 }
1849 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1850
1851 status = p.readInt32(&t);
1852 if (status != NO_ERROR) {
1853 goto invalid;
1854 }
1855 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1856
1857 startRequest;
1858 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1859 uicc_sub.act_status);
1860 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1861 uicc_sub.app_index, uicc_sub.act_status);
1862 closeRequest;
1863 printRequest(pRI->token, pRI->pCI->requestNumber);
1864
1865 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1866
1867#ifdef MEMSET_FREED
1868 memset(&uicc_sub, 0, sizeof(uicc_sub));
1869#endif
1870 return;
1871
1872invalid:
1873 invalidCommandBlock(pRI);
1874 return;
1875}
1876
Amit Mahajan90530a62014-07-01 15:54:08 -07001877static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1878{
1879 RIL_SimAuthentication pf;
1880 int32_t t;
1881 status_t status;
1882
1883 memset(&pf, 0, sizeof(pf));
1884
1885 status = p.readInt32(&t);
1886 pf.authContext = (int) t;
1887 pf.authData = strdupReadString(p);
1888 pf.aid = strdupReadString(p);
1889
1890 startRequest;
1891 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1892 closeRequest;
1893 printRequest(pRI->token, pRI->pCI->requestNumber);
1894
1895 if (status != NO_ERROR) {
1896 goto invalid;
1897 }
1898 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1899
1900#ifdef MEMSET_FREED
1901 memsetString(pf.authData);
1902 memsetString(pf.aid);
1903#endif
1904
1905 free(pf.authData);
1906 free(pf.aid);
1907
1908#ifdef MEMSET_FREED
1909 memset(&pf, 0, sizeof(pf));
1910#endif
1911
1912 return;
1913invalid:
1914 invalidCommandBlock(pRI);
1915 return;
1916}
1917
Amit Mahajanc796e222014-08-13 16:54:01 +00001918static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1919 int32_t t;
1920 status_t status;
1921 int32_t num;
1922
1923 status = p.readInt32(&num);
1924 if (status != NO_ERROR) {
1925 goto invalid;
1926 }
1927
1928 {
1929 RIL_DataProfileInfo dataProfiles[num];
1930 RIL_DataProfileInfo *dataProfilePtrs[num];
1931
1932 startRequest;
1933 for (int i = 0 ; i < num ; i++ ) {
1934 dataProfilePtrs[i] = &dataProfiles[i];
1935
1936 status = p.readInt32(&t);
1937 dataProfiles[i].profileId = (int) t;
1938
1939 dataProfiles[i].apn = strdupReadString(p);
1940 dataProfiles[i].protocol = strdupReadString(p);
1941 status = p.readInt32(&t);
1942 dataProfiles[i].authType = (int) t;
1943
1944 dataProfiles[i].user = strdupReadString(p);
1945 dataProfiles[i].password = strdupReadString(p);
1946
1947 status = p.readInt32(&t);
1948 dataProfiles[i].type = (int) t;
1949
1950 status = p.readInt32(&t);
1951 dataProfiles[i].maxConnsTime = (int) t;
1952 status = p.readInt32(&t);
1953 dataProfiles[i].maxConns = (int) t;
1954 status = p.readInt32(&t);
1955 dataProfiles[i].waitTime = (int) t;
1956
1957 status = p.readInt32(&t);
1958 dataProfiles[i].enabled = (int) t;
1959
1960 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1961 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1962 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1963 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1964 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1965 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1966 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1967 }
1968 closeRequest;
1969 printRequest(pRI->token, pRI->pCI->requestNumber);
1970
1971 if (status != NO_ERROR) {
1972 goto invalid;
1973 }
1974 CALL_ONREQUEST(pRI->pCI->requestNumber,
1975 dataProfilePtrs,
1976 num * sizeof(RIL_DataProfileInfo *),
1977 pRI, pRI->socket_id);
1978
1979#ifdef MEMSET_FREED
1980 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1981 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1982#endif
1983 }
1984
1985 return;
1986
1987invalid:
1988 invalidCommandBlock(pRI);
1989 return;
1990}
1991
Wink Saville8b4e4f72014-10-17 15:01:45 -07001992static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1993 RIL_RadioCapability rc;
1994 int32_t t;
1995 status_t status;
1996
1997 memset (&rc, 0, sizeof(RIL_RadioCapability));
1998
1999 status = p.readInt32(&t);
2000 rc.version = (int)t;
2001 if (status != NO_ERROR) {
2002 goto invalid;
2003 }
2004
2005 status = p.readInt32(&t);
2006 rc.session= (int)t;
2007 if (status != NO_ERROR) {
2008 goto invalid;
2009 }
2010
2011 status = p.readInt32(&t);
2012 rc.phase= (int)t;
2013 if (status != NO_ERROR) {
2014 goto invalid;
2015 }
2016
2017 status = p.readInt32(&t);
2018 rc.rat = (int)t;
2019 if (status != NO_ERROR) {
2020 goto invalid;
2021 }
2022
2023 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2024 if (status != NO_ERROR) {
2025 goto invalid;
2026 }
2027
2028 status = p.readInt32(&t);
2029 rc.status = (int)t;
2030
2031 if (status != NO_ERROR) {
2032 goto invalid;
2033 }
2034
2035 startRequest;
2036 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002037 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2038 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002039
2040 closeRequest;
2041 printRequest(pRI->token, pRI->pCI->requestNumber);
2042
2043 CALL_ONREQUEST(pRI->pCI->requestNumber,
2044 &rc,
2045 sizeof(RIL_RadioCapability),
2046 pRI, pRI->socket_id);
2047 return;
2048invalid:
2049 invalidCommandBlock(pRI);
2050 return;
2051}
2052
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002053static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002054blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002055 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002056 const uint8_t *toWrite;
2057
2058 toWrite = (const uint8_t *)buffer;
2059
2060 while (writeOffset < len) {
2061 ssize_t written;
2062 do {
2063 written = write (fd, toWrite + writeOffset,
2064 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302065 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002066
2067 if (written >= 0) {
2068 writeOffset += written;
2069 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002070 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002071 close(fd);
2072 return -1;
2073 }
2074 }
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002075#if VDBG
Dheeraj Shetty27976c42014-07-02 21:27:57 +02002076 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002077#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002078 return 0;
2079}
2080
2081static int
Etan Cohend3652192014-06-20 08:28:44 -07002082sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2083 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002084 int ret;
2085 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002086 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002087
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002088#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07002089 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07002090#endif
Etan Cohend3652192014-06-20 08:28:44 -07002091
2092#if (SIM_COUNT >= 2)
2093 if (socket_id == RIL_SOCKET_2) {
2094 fd = s_ril_param_socket2.fdCommand;
2095 writeMutexHook = &s_writeMutex_socket2;
2096 }
2097#if (SIM_COUNT >= 3)
2098 else if (socket_id == RIL_SOCKET_3) {
2099 fd = s_ril_param_socket3.fdCommand;
2100 writeMutexHook = &s_writeMutex_socket3;
2101 }
2102#endif
2103#if (SIM_COUNT >= 4)
2104 else if (socket_id == RIL_SOCKET_4) {
2105 fd = s_ril_param_socket4.fdCommand;
2106 writeMutexHook = &s_writeMutex_socket4;
2107 }
2108#endif
2109#endif
2110 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002111 return -1;
2112 }
2113
2114 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002115 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002116 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2117
2118 return -1;
2119 }
Wink Saville7f856802009-06-09 10:23:37 -07002120
Etan Cohend3652192014-06-20 08:28:44 -07002121 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002122
2123 header = htonl(dataSize);
2124
2125 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2126
2127 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002128 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002129 return ret;
2130 }
2131
Kennyee1fadc2009-08-13 00:45:53 +08002132 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002133
2134 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002135 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136 return ret;
2137 }
2138
Etan Cohend3652192014-06-20 08:28:44 -07002139 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002140
2141 return 0;
2142}
2143
2144static int
Etan Cohend3652192014-06-20 08:28:44 -07002145sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002146 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002147 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002148}
2149
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002150/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002151
2152static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002153responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002154 int numInts;
2155
2156 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002157 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002158 return RIL_ERRNO_INVALID_RESPONSE;
2159 }
2160 if (responselen % sizeof(int) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002161 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002162 (int)responselen, (int)sizeof(int));
2163 return RIL_ERRNO_INVALID_RESPONSE;
2164 }
2165
2166 int *p_int = (int *) response;
2167
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002168 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002169 p.writeInt32 (numInts);
2170
2171 /* each int*/
2172 startResponse;
2173 for (int i = 0 ; i < numInts ; i++) {
2174 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2175 p.writeInt32(p_int[i]);
2176 }
2177 removeLastChar;
2178 closeResponse;
2179
2180 return 0;
2181}
2182
Chao Liu548a81e2015-05-14 16:13:46 -07002183// Response is an int or RIL_LastCallFailCauseInfo.
2184// Currently, only Shamu plans to use RIL_LastCallFailCauseInfo.
2185// TODO(yjl): Let all implementations use RIL_LastCallFailCauseInfo.
2186static int responseFailCause(Parcel &p, void *response, size_t responselen) {
2187 if (response == NULL && responselen != 0) {
2188 RLOGE("invalid response: NULL");
2189 return RIL_ERRNO_INVALID_RESPONSE;
2190 }
2191
2192 if (responselen == sizeof(int)) {
Sungmin Choia408c252015-07-01 16:22:46 +09002193 startResponse;
2194 int *p_int = (int *) response;
2195 appendPrintBuf("%s%d,", printBuf, p_int[0]);
2196 p.writeInt32(p_int[0]);
2197 removeLastChar;
2198 closeResponse;
Chao Liu548a81e2015-05-14 16:13:46 -07002199 } else if (responselen == sizeof(RIL_LastCallFailCauseInfo)) {
2200 startResponse;
2201 RIL_LastCallFailCauseInfo *p_fail_cause_info = (RIL_LastCallFailCauseInfo *) response;
2202 appendPrintBuf("%s[cause_code=%d,vendor_cause=%s]", printBuf, p_fail_cause_info->cause_code,
2203 p_fail_cause_info->vendor_cause);
2204 p.writeInt32(p_fail_cause_info->cause_code);
2205 writeStringToParcel(p, p_fail_cause_info->vendor_cause);
2206 removeLastChar;
2207 closeResponse;
2208 } else {
2209 RLOGE("responseFailCause: invalid response length %d expected an int or "
2210 "RIL_LastCallFailCauseInfo", (int)responselen);
2211 return RIL_ERRNO_INVALID_RESPONSE;
2212 }
2213
2214 return 0;
2215}
2216
Wink Saville43808972011-01-13 17:39:51 -08002217/** response is a char **, pointing to an array of char *'s
2218 The parcel will begin with the version */
2219static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2220 p.writeInt32(version);
2221 return responseStrings(p, response, responselen);
2222}
2223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002224/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07002225static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002226 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07002227
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002228 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002229 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002230 return RIL_ERRNO_INVALID_RESPONSE;
2231 }
2232 if (responselen % sizeof(char *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002233 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002234 (int)responselen, (int)sizeof(char *));
2235 return RIL_ERRNO_INVALID_RESPONSE;
2236 }
2237
2238 if (response == NULL) {
2239 p.writeInt32 (0);
2240 } else {
2241 char **p_cur = (char **) response;
2242
2243 numStrings = responselen / sizeof(char *);
2244 p.writeInt32 (numStrings);
2245
2246 /* each string*/
2247 startResponse;
2248 for (int i = 0 ; i < numStrings ; i++) {
2249 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2250 writeStringToParcel (p, p_cur[i]);
2251 }
2252 removeLastChar;
2253 closeResponse;
2254 }
2255 return 0;
2256}
2257
2258
2259/**
Wink Saville7f856802009-06-09 10:23:37 -07002260 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002261 * FIXME currently ignores responselen
2262 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002263static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002264 /* one string only */
2265 startResponse;
2266 appendPrintBuf("%s%s", printBuf, (char*)response);
2267 closeResponse;
2268
2269 writeStringToParcel(p, (const char *)response);
2270
2271 return 0;
2272}
2273
Wink Savillef4c4d362009-04-02 01:37:03 -07002274static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002275 startResponse;
2276 removeLastChar;
2277 return 0;
2278}
2279
Wink Savillef4c4d362009-04-02 01:37:03 -07002280static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002281 int num;
2282
2283 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002284 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002285 return RIL_ERRNO_INVALID_RESPONSE;
2286 }
2287
2288 if (responselen % sizeof (RIL_Call *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002289 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002290 (int)responselen, (int)sizeof (RIL_Call *));
2291 return RIL_ERRNO_INVALID_RESPONSE;
2292 }
2293
2294 startResponse;
2295 /* number of call info's */
2296 num = responselen / sizeof(RIL_Call *);
2297 p.writeInt32(num);
2298
2299 for (int i = 0 ; i < num ; i++) {
2300 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2301 /* each call info */
2302 p.writeInt32(p_cur->state);
2303 p.writeInt32(p_cur->index);
2304 p.writeInt32(p_cur->toa);
2305 p.writeInt32(p_cur->isMpty);
2306 p.writeInt32(p_cur->isMT);
2307 p.writeInt32(p_cur->als);
2308 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002309 p.writeInt32(p_cur->isVoicePrivacy);
2310 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002311 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002312 writeStringToParcel(p, p_cur->name);
2313 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002314 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002315 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2316 p.writeInt32(0); /* UUS Information is absent */
2317 } else {
2318 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2319 p.writeInt32(1); /* UUS Information is present */
2320 p.writeInt32(uusInfo->uusType);
2321 p.writeInt32(uusInfo->uusDcs);
2322 p.writeInt32(uusInfo->uusLength);
2323 p.write(uusInfo->uusData, uusInfo->uusLength);
2324 }
Wink Saville3d54e742009-05-18 18:00:44 -07002325 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002326 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002327 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002328 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002329 p_cur->toa);
2330 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2331 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002332 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002333 (p_cur->isMT)?"mt":"mo",
2334 p_cur->als,
2335 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002336 (p_cur->isVoicePrivacy)?"evp":"noevp");
2337 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2338 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002339 p_cur->number,
2340 p_cur->numberPresentation,
2341 p_cur->name,
2342 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002343 }
2344 removeLastChar;
2345 closeResponse;
2346
2347 return 0;
2348}
2349
Wink Savillef4c4d362009-04-02 01:37:03 -07002350static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002351 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002352 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002353 return RIL_ERRNO_INVALID_RESPONSE;
2354 }
2355
2356 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002357 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002358 (int)responselen, (int)sizeof (RIL_SMS_Response));
2359 return RIL_ERRNO_INVALID_RESPONSE;
2360 }
2361
2362 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2363
2364 p.writeInt32(p_cur->messageRef);
2365 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002366 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002367
2368 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002369 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2370 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002371 closeResponse;
2372
2373 return 0;
2374}
2375
Wink Savillec0114b32011-02-18 10:14:07 -08002376static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002377{
2378 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002379 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002380 return RIL_ERRNO_INVALID_RESPONSE;
2381 }
2382
Wink Savillec0114b32011-02-18 10:14:07 -08002383 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002384 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002385 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002386 return RIL_ERRNO_INVALID_RESPONSE;
2387 }
2388
Amit Mahajan52500162014-07-29 17:36:48 -07002389 // Write version
2390 p.writeInt32(4);
2391
Wink Savillec0114b32011-02-18 10:14:07 -08002392 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002393 p.writeInt32(num);
2394
Wink Savillec0114b32011-02-18 10:14:07 -08002395 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002396 startResponse;
2397 int i;
2398 for (i = 0; i < num; i++) {
2399 p.writeInt32(p_cur[i].cid);
2400 p.writeInt32(p_cur[i].active);
2401 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002402 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002403 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002404 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002405 p_cur[i].cid,
2406 (p_cur[i].active==0)?"down":"up",
2407 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002408 (char*)p_cur[i].address);
2409 }
2410 removeLastChar;
2411 closeResponse;
2412
2413 return 0;
2414}
2415
Etan Cohend3652192014-06-20 08:28:44 -07002416static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2417{
Amit Mahajan52500162014-07-29 17:36:48 -07002418 if (response == NULL && responselen != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002419 RLOGE("invalid response: NULL");
2420 return RIL_ERRNO_INVALID_RESPONSE;
2421 }
2422
2423 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002424 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002425 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2426 return RIL_ERRNO_INVALID_RESPONSE;
2427 }
2428
Amit Mahajan52500162014-07-29 17:36:48 -07002429 // Write version
2430 p.writeInt32(6);
2431
Etan Cohend3652192014-06-20 08:28:44 -07002432 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2433 p.writeInt32(num);
2434
2435 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2436 startResponse;
2437 int i;
2438 for (i = 0; i < num; i++) {
2439 p.writeInt32((int)p_cur[i].status);
2440 p.writeInt32(p_cur[i].suggestedRetryTime);
2441 p.writeInt32(p_cur[i].cid);
2442 p.writeInt32(p_cur[i].active);
2443 writeStringToParcel(p, p_cur[i].type);
2444 writeStringToParcel(p, p_cur[i].ifname);
2445 writeStringToParcel(p, p_cur[i].addresses);
2446 writeStringToParcel(p, p_cur[i].dnses);
2447 writeStringToParcel(p, p_cur[i].gateways);
2448 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2449 p_cur[i].status,
2450 p_cur[i].suggestedRetryTime,
2451 p_cur[i].cid,
2452 (p_cur[i].active==0)?"down":"up",
2453 (char*)p_cur[i].type,
2454 (char*)p_cur[i].ifname,
2455 (char*)p_cur[i].addresses,
2456 (char*)p_cur[i].dnses,
2457 (char*)p_cur[i].gateways);
2458 }
2459 removeLastChar;
2460 closeResponse;
2461
2462 return 0;
2463}
2464
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002465static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2466{
2467 if (response == NULL && responselen != 0) {
2468 RLOGE("invalid response: NULL");
2469 return RIL_ERRNO_INVALID_RESPONSE;
2470 }
2471
2472 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2473 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2474 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2475 return RIL_ERRNO_INVALID_RESPONSE;
2476 }
2477
2478 // Write version
2479 p.writeInt32(10);
2480
2481 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2482 p.writeInt32(num);
2483
2484 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2485 startResponse;
2486 int i;
2487 for (i = 0; i < num; i++) {
2488 p.writeInt32((int)p_cur[i].status);
2489 p.writeInt32(p_cur[i].suggestedRetryTime);
2490 p.writeInt32(p_cur[i].cid);
2491 p.writeInt32(p_cur[i].active);
2492 writeStringToParcel(p, p_cur[i].type);
2493 writeStringToParcel(p, p_cur[i].ifname);
2494 writeStringToParcel(p, p_cur[i].addresses);
2495 writeStringToParcel(p, p_cur[i].dnses);
2496 writeStringToParcel(p, p_cur[i].gateways);
2497 writeStringToParcel(p, p_cur[i].pcscf);
2498 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2499 p_cur[i].status,
2500 p_cur[i].suggestedRetryTime,
2501 p_cur[i].cid,
2502 (p_cur[i].active==0)?"down":"up",
2503 (char*)p_cur[i].type,
2504 (char*)p_cur[i].ifname,
2505 (char*)p_cur[i].addresses,
2506 (char*)p_cur[i].dnses,
2507 (char*)p_cur[i].gateways,
2508 (char*)p_cur[i].pcscf);
2509 }
2510 removeLastChar;
2511 closeResponse;
2512
2513 return 0;
2514}
2515
2516
Wink Saville43808972011-01-13 17:39:51 -08002517static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2518{
Wink Saville43808972011-01-13 17:39:51 -08002519 if (s_callbacks.version < 5) {
Amit Mahajan52500162014-07-29 17:36:48 -07002520 RLOGD("responseDataCallList: v4");
Wink Savillec0114b32011-02-18 10:14:07 -08002521 return responseDataCallListV4(p, response, responselen);
Sukanya Rajkhowaf2abf702014-09-25 15:47:26 -07002522 } else if (s_callbacks.version < 10) {
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002523 return responseDataCallListV6(p, response, responselen);
Sukanya Rajkhowaf2abf702014-09-25 15:47:26 -07002524 } else if (s_callbacks.version == 10) {
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002525 return responseDataCallListV9(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002526 } else {
2527 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002528 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002529 return RIL_ERRNO_INVALID_RESPONSE;
2530 }
2531
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002532 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2533 RLOGE("invalid response length %d expected multiple of %d",
2534 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Wink Saville43808972011-01-13 17:39:51 -08002535 return RIL_ERRNO_INVALID_RESPONSE;
2536 }
2537
Amit Mahajan52500162014-07-29 17:36:48 -07002538 // Write version
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002539 p.writeInt32(11);
Amit Mahajan52500162014-07-29 17:36:48 -07002540
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002541 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Wink Saville43808972011-01-13 17:39:51 -08002542 p.writeInt32(num);
2543
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002544 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002545 startResponse;
2546 int i;
2547 for (i = 0; i < num; i++) {
2548 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002549 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002550 p.writeInt32(p_cur[i].cid);
2551 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002552 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002553 writeStringToParcel(p, p_cur[i].ifname);
2554 writeStringToParcel(p, p_cur[i].addresses);
2555 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002556 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002557 writeStringToParcel(p, p_cur[i].pcscf);
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002558 p.writeInt32(p_cur[i].mtu);
2559 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002560 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002561 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002562 p_cur[i].cid,
2563 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002564 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002565 (char*)p_cur[i].ifname,
2566 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002567 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002568 (char*)p_cur[i].gateways,
Sukanya Rajkhowab44dda32014-06-02 14:03:44 -07002569 (char*)p_cur[i].pcscf,
2570 p_cur[i].mtu);
Wink Saville43808972011-01-13 17:39:51 -08002571 }
2572 removeLastChar;
2573 closeResponse;
2574 }
2575
2576 return 0;
2577}
2578
2579static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2580{
2581 if (s_callbacks.version < 5) {
2582 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2583 } else {
2584 return responseDataCallList(p, response, responselen);
2585 }
2586}
2587
Wink Savillef4c4d362009-04-02 01:37:03 -07002588static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002589 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002590 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002591 return RIL_ERRNO_INVALID_RESPONSE;
2592 }
2593
2594 // The java code reads -1 size as null byte array
2595 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002596 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002597 } else {
2598 p.writeInt32(responselen);
2599 p.write(response, responselen);
2600 }
2601
2602 return 0;
2603}
2604
2605
Wink Savillef4c4d362009-04-02 01:37:03 -07002606static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002607 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002608 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002609 return RIL_ERRNO_INVALID_RESPONSE;
2610 }
2611
2612 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002613 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002614 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2615 return RIL_ERRNO_INVALID_RESPONSE;
2616 }
2617
2618 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2619 p.writeInt32(p_cur->sw1);
2620 p.writeInt32(p_cur->sw2);
2621 writeStringToParcel(p, p_cur->simResponse);
2622
2623 startResponse;
2624 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2625 (char*)p_cur->simResponse);
2626 closeResponse;
2627
2628
2629 return 0;
2630}
2631
Wink Savillef4c4d362009-04-02 01:37:03 -07002632static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002633 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002634
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002635 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002636 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002637 return RIL_ERRNO_INVALID_RESPONSE;
2638 }
2639
2640 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002641 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002642 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2643 return RIL_ERRNO_INVALID_RESPONSE;
2644 }
2645
2646 /* number of call info's */
2647 num = responselen / sizeof(RIL_CallForwardInfo *);
2648 p.writeInt32(num);
2649
2650 startResponse;
2651 for (int i = 0 ; i < num ; i++) {
2652 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2653
2654 p.writeInt32(p_cur->status);
2655 p.writeInt32(p_cur->reason);
2656 p.writeInt32(p_cur->serviceClass);
2657 p.writeInt32(p_cur->toa);
2658 writeStringToParcel(p, p_cur->number);
2659 p.writeInt32(p_cur->timeSeconds);
2660 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2661 (p_cur->status==1)?"enable":"disable",
2662 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2663 (char*)p_cur->number,
2664 p_cur->timeSeconds);
2665 }
2666 removeLastChar;
2667 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002668
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002669 return 0;
2670}
2671
Wink Savillef4c4d362009-04-02 01:37:03 -07002672static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002673 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002674 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002675 return RIL_ERRNO_INVALID_RESPONSE;
2676 }
2677
2678 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002679 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002680 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2681 return RIL_ERRNO_INVALID_RESPONSE;
2682 }
2683
2684 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2685 p.writeInt32(p_cur->notificationType);
2686 p.writeInt32(p_cur->code);
2687 p.writeInt32(p_cur->index);
2688 p.writeInt32(p_cur->type);
2689 writeStringToParcel(p, p_cur->number);
2690
2691 startResponse;
2692 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2693 (p_cur->notificationType==0)?"mo":"mt",
2694 p_cur->code, p_cur->index, p_cur->type,
2695 (char*)p_cur->number);
2696 closeResponse;
2697
2698 return 0;
2699}
2700
Wink Saville3d54e742009-05-18 18:00:44 -07002701static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002702 int num;
2703
2704 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002705 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002706 return RIL_ERRNO_INVALID_RESPONSE;
2707 }
2708
2709 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07002710 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002711 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2712 return RIL_ERRNO_INVALID_RESPONSE;
2713 }
2714
2715 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002716 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002717 num = responselen / sizeof(RIL_NeighboringCell *);
2718 p.writeInt32(num);
2719
2720 for (int i = 0 ; i < num ; i++) {
2721 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2722
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002723 p.writeInt32(p_cur->rssi);
2724 writeStringToParcel (p, p_cur->cid);
2725
2726 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2727 p_cur->cid, p_cur->rssi);
2728 }
2729 removeLastChar;
2730 closeResponse;
2731
2732 return 0;
2733}
2734
Wink Saville3d54e742009-05-18 18:00:44 -07002735/**
2736 * Marshall the signalInfoRecord into the parcel if it exists.
2737 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002738static void marshallSignalInfoRecord(Parcel &p,
2739 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002740 p.writeInt32(p_signalInfoRecord.isPresent);
2741 p.writeInt32(p_signalInfoRecord.signalType);
2742 p.writeInt32(p_signalInfoRecord.alertPitch);
2743 p.writeInt32(p_signalInfoRecord.signal);
2744}
2745
Wink Savillea592eeb2009-05-22 13:26:36 -07002746static int responseCdmaInformationRecords(Parcel &p,
2747 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002748 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002749 char* string8 = NULL;
2750 int buffer_lenght;
2751 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002752
2753 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002754 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002755 return RIL_ERRNO_INVALID_RESPONSE;
2756 }
2757
Wink Savillea592eeb2009-05-22 13:26:36 -07002758 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Amit Mahajan52500162014-07-29 17:36:48 -07002759 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002760 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002761 return RIL_ERRNO_INVALID_RESPONSE;
2762 }
2763
Wink Savillea592eeb2009-05-22 13:26:36 -07002764 RIL_CDMA_InformationRecords *p_cur =
2765 (RIL_CDMA_InformationRecords *) response;
2766 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002767
2768 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002769 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002770
Wink Savillea592eeb2009-05-22 13:26:36 -07002771 for (int i = 0 ; i < num ; i++) {
2772 infoRec = &p_cur->infoRec[i];
2773 p.writeInt32(infoRec->name);
2774 switch (infoRec->name) {
Wink Savillea592eeb2009-05-22 13:26:36 -07002775 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2776 if (infoRec->rec.display.alpha_len >
2777 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002778 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002779 expected not more than %d\n",
2780 (int)infoRec->rec.display.alpha_len,
2781 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2782 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002783 }
Sukanya Rajkhowa310ce702010-06-23 20:14:04 -07002784 // Write as a byteArray
2785 p.writeInt32(infoRec->rec.display.alpha_len);
2786 p.write(infoRec->rec.display.alpha_buf,
2787 infoRec->rec.display.alpha_len);
2788 break;
2789 case RIL_CDMA_DISPLAY_INFO_REC:
2790 if (infoRec->rec.display.alpha_len >
2791 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
2792 RLOGE("invalid display info response length %d \
2793 expected not more than %d\n",
2794 (int)infoRec->rec.display.alpha_len,
2795 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2796 return RIL_ERRNO_INVALID_RESPONSE;
2797 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002798 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2799 * sizeof(char) );
2800 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2801 string8[i] = infoRec->rec.display.alpha_buf[i];
2802 }
Wink Saville43808972011-01-13 17:39:51 -08002803 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002804 writeStringToParcel(p, (const char*)string8);
2805 free(string8);
2806 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002807 break;
2808 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002809 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002810 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002811 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002812 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002813 expected not more than %d\n",
2814 (int)infoRec->rec.number.len,
2815 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2816 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002817 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002818 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2819 * sizeof(char) );
2820 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2821 string8[i] = infoRec->rec.number.buf[i];
2822 }
Wink Saville43808972011-01-13 17:39:51 -08002823 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002824 writeStringToParcel(p, (const char*)string8);
2825 free(string8);
2826 string8 = NULL;
2827 p.writeInt32(infoRec->rec.number.number_type);
2828 p.writeInt32(infoRec->rec.number.number_plan);
2829 p.writeInt32(infoRec->rec.number.pi);
2830 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002831 break;
2832 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002833 p.writeInt32(infoRec->rec.signal.isPresent);
2834 p.writeInt32(infoRec->rec.signal.signalType);
2835 p.writeInt32(infoRec->rec.signal.alertPitch);
2836 p.writeInt32(infoRec->rec.signal.signal);
2837
2838 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2839 alertPitch=%X, signal=%X, ",
2840 printBuf, (int)infoRec->rec.signal.isPresent,
2841 (int)infoRec->rec.signal.signalType,
2842 (int)infoRec->rec.signal.alertPitch,
2843 (int)infoRec->rec.signal.signal);
2844 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002845 break;
2846 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002847 if (infoRec->rec.redir.redirectingNumber.len >
2848 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002849 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002850 expected not more than %d\n",
2851 (int)infoRec->rec.redir.redirectingNumber.len,
2852 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2853 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002854 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002855 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2856 .len + 1) * sizeof(char) );
2857 for (int i = 0;
2858 i < infoRec->rec.redir.redirectingNumber.len;
2859 i++) {
2860 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2861 }
Wink Saville43808972011-01-13 17:39:51 -08002862 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002863 writeStringToParcel(p, (const char*)string8);
2864 free(string8);
2865 string8 = NULL;
2866 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2867 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2868 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2869 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2870 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002871 break;
2872 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002873 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2874 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2875 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2876 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2877
2878 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2879 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2880 lineCtrlPowerDenial=%d, ", printBuf,
2881 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2882 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2883 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2884 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2885 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002886 break;
2887 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002888 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002889
Wink Savillea592eeb2009-05-22 13:26:36 -07002890 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2891 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002892 break;
2893 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002894 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2895 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2896
2897 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2898 infoRec->rec.audioCtrl.upLink,
2899 infoRec->rec.audioCtrl.downLink);
2900 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002901 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002902 case RIL_CDMA_T53_RELEASE_INFO_REC:
2903 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002904 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002905 return RIL_ERRNO_INVALID_RESPONSE;
2906 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002907 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002908 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002909 }
2910 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002911 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002912
Wink Savillea592eeb2009-05-22 13:26:36 -07002913 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002914}
2915
Wink Savillea592eeb2009-05-22 13:26:36 -07002916static int responseRilSignalStrength(Parcel &p,
2917 void *response, size_t responselen) {
2918 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002919 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002920 return RIL_ERRNO_INVALID_RESPONSE;
2921 }
2922
Wink Savillec0114b32011-02-18 10:14:07 -08002923 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002924 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002925
Wink Saville3d54e742009-05-18 18:00:44 -07002926 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2927 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2928 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2929 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2930 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2931 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2932 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002933 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002934 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002935 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002936 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002937 if (s_callbacks.version <= 6) {
2938 // signalStrength: -1 -> 99
2939 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2940 p_cur->LTE_SignalStrength.signalStrength = 99;
2941 }
2942 // rsrp: -1 -> INT_MAX all other negative value to positive.
2943 // So remap here
2944 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2945 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2946 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2947 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2948 }
2949 // rsrq: -1 -> INT_MAX
2950 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2951 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2952 }
2953 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002954
Wink Saville18e4ab12013-04-07 17:31:04 -07002955 // cqi: -1 -> INT_MAX
2956 if (p_cur->LTE_SignalStrength.cqi == -1) {
2957 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2958 }
2959 }
2960 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002961 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2962 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2963 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2964 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002965 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2966 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2967 } else {
2968 p.writeInt32(INT_MAX);
2969 }
Wink Savillec0114b32011-02-18 10:14:07 -08002970 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002971 p.writeInt32(99);
2972 p.writeInt32(INT_MAX);
2973 p.writeInt32(INT_MAX);
2974 p.writeInt32(INT_MAX);
2975 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002976 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002977 }
johnwangfdf825f2009-05-22 15:50:34 -07002978
2979 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002980 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002981 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2982 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2983 EVDO_SS.signalNoiseRatio=%d,\
2984 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002985 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002986 printBuf,
2987 p_cur->GW_SignalStrength.signalStrength,
2988 p_cur->GW_SignalStrength.bitErrorRate,
2989 p_cur->CDMA_SignalStrength.dbm,
2990 p_cur->CDMA_SignalStrength.ecio,
2991 p_cur->EVDO_SignalStrength.dbm,
2992 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002993 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2994 p_cur->LTE_SignalStrength.signalStrength,
2995 p_cur->LTE_SignalStrength.rsrp,
2996 p_cur->LTE_SignalStrength.rsrq,
2997 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002998 p_cur->LTE_SignalStrength.cqi,
2999 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07003000 closeResponse;
3001
Wink Saville3d54e742009-05-18 18:00:44 -07003002 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003003 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07003004 return RIL_ERRNO_INVALID_RESPONSE;
3005 }
3006
Wink Saville3d54e742009-05-18 18:00:44 -07003007 return 0;
3008}
3009
3010static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3011 if ((response == NULL) || (responselen == 0)) {
3012 return responseVoid(p, response, responselen);
3013 } else {
3014 return responseCdmaSignalInfoRecord(p, response, responselen);
3015 }
3016}
3017
3018static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3019 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003020 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003021 return RIL_ERRNO_INVALID_RESPONSE;
3022 }
3023
3024 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003025 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07003026 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3027 return RIL_ERRNO_INVALID_RESPONSE;
3028 }
3029
3030 startResponse;
3031
3032 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3033 marshallSignalInfoRecord(p, *p_cur);
3034
3035 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3036 signal=%d]",
3037 printBuf,
3038 p_cur->isPresent,
3039 p_cur->signalType,
3040 p_cur->alertPitch,
3041 p_cur->signal);
3042
3043 closeResponse;
3044 return 0;
3045}
3046
Wink Savillea592eeb2009-05-22 13:26:36 -07003047static int responseCdmaCallWaiting(Parcel &p, void *response,
3048 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07003049 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003050 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07003051 return RIL_ERRNO_INVALID_RESPONSE;
3052 }
3053
Wink Savillec0114b32011-02-18 10:14:07 -08003054 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003055 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08003056 }
3057
3058 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3059
3060 writeStringToParcel(p, p_cur->number);
3061 p.writeInt32(p_cur->numberPresentation);
3062 writeStringToParcel(p, p_cur->name);
3063 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3064
3065 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3066 p.writeInt32(p_cur->number_type);
3067 p.writeInt32(p_cur->number_plan);
3068 } else {
3069 p.writeInt32(0);
3070 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07003071 }
3072
3073 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07003074 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3075 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08003076 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07003077 printBuf,
3078 p_cur->number,
3079 p_cur->numberPresentation,
3080 p_cur->name,
3081 p_cur->signalInfoRecord.isPresent,
3082 p_cur->signalInfoRecord.signalType,
3083 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08003084 p_cur->signalInfoRecord.signal,
3085 p_cur->number_type,
3086 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07003087 closeResponse;
3088
3089 return 0;
3090}
3091
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003092static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3093 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003094 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003095 return RIL_ERRNO_INVALID_RESPONSE;
3096 }
3097
3098 startResponse;
Rakesh Pallerlab31c3242014-01-10 17:53:15 +05303099 if (s_callbacks.version >= 7) {
Alex Yakavenka45e740e2012-01-31 11:48:27 -08003100 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3101 p.writeInt32(p_cur->result);
3102 p.writeInt32(p_cur->ef_id);
3103 writeStringToParcel(p, p_cur->aid);
3104
3105 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3106 printBuf,
3107 p_cur->result,
3108 p_cur->ef_id,
3109 p_cur->aid);
3110 } else {
3111 int *p_cur = ((int *) response);
3112 p.writeInt32(p_cur[0]);
3113 p.writeInt32(p_cur[1]);
3114 writeStringToParcel(p, NULL);
3115
3116 appendPrintBuf("%sresult=%d, ef_id=%d",
3117 printBuf,
3118 p_cur[0],
3119 p_cur[1]);
3120 }
3121 closeResponse;
3122
3123 return 0;
3124}
3125
Wink Saville8a9e0212013-04-09 12:11:38 -07003126static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3127{
3128 if (response == NULL && responselen != 0) {
3129 RLOGE("invalid response: NULL");
3130 return RIL_ERRNO_INVALID_RESPONSE;
3131 }
3132
3133 if (responselen % sizeof(RIL_CellInfo) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003134 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
Wink Saville8a9e0212013-04-09 12:11:38 -07003135 (int)responselen, (int)sizeof(RIL_CellInfo));
3136 return RIL_ERRNO_INVALID_RESPONSE;
3137 }
3138
3139 int num = responselen / sizeof(RIL_CellInfo);
3140 p.writeInt32(num);
3141
3142 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3143 startResponse;
3144 int i;
3145 for (i = 0; i < num; i++) {
3146 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3147 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3148 p.writeInt32((int)p_cur->cellInfoType);
3149 p.writeInt32(p_cur->registered);
3150 p.writeInt32(p_cur->timeStampType);
3151 p.writeInt64(p_cur->timeStamp);
3152 switch(p_cur->cellInfoType) {
3153 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07003154 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003155 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3156 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3157 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07003158 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3159 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07003160 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3161 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3162
3163 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3164 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3165 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3166 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07003167 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3168 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3169 break;
3170 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07003171 case RIL_CELL_INFO_TYPE_WCDMA: {
3172 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3173 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3174 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3175 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3176 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3177 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3178 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3179 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3180 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3181
3182 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3183 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3184 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3185 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3186 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3187 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3188 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3189 break;
3190 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003191 case RIL_CELL_INFO_TYPE_CDMA: {
3192 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3193 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3194 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3195 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3196 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3197 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3198
3199 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3200 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3201 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3202 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3203 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3204
3205 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3206 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3207 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3208 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3209 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3210 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3211
3212 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3213 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3214 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3215 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3216 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3217 break;
3218 }
3219 case RIL_CELL_INFO_TYPE_LTE: {
3220 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3221 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3222 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3223 p_cur->CellInfo.lte.cellIdentityLte.ci,
3224 p_cur->CellInfo.lte.cellIdentityLte.pci,
3225 p_cur->CellInfo.lte.cellIdentityLte.tac);
3226
3227 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3228 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3229 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3230 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3231 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3232
3233 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3234 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3235 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3236 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3237 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3238 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3239 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3240 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3241 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3242 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3243 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3244 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3245 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3246 break;
3247 }
Etan Cohend3652192014-06-20 08:28:44 -07003248 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3249 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3250 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3251 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3252 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3253 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3254 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3255 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3256 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3257
3258 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3259 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3260 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3261 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3262 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3263 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3264 break;
3265 }
Wink Saville8a9e0212013-04-09 12:11:38 -07003266 }
3267 p_cur += 1;
3268 }
3269 removeLastChar;
3270 closeResponse;
3271
3272 return 0;
3273}
3274
Etan Cohend3652192014-06-20 08:28:44 -07003275static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3276{
3277 if (response == NULL && responselen != 0) {
3278 RLOGE("invalid response: NULL");
3279 return RIL_ERRNO_INVALID_RESPONSE;
3280 }
3281
3282 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
Amit Mahajan52500162014-07-29 17:36:48 -07003283 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07003284 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3285 return RIL_ERRNO_INVALID_RESPONSE;
3286 }
3287
3288 int num = responselen / sizeof(RIL_HardwareConfig);
3289 int i;
3290 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3291
3292 p.writeInt32(num);
3293
3294 startResponse;
3295 for (i = 0; i < num; i++) {
3296 switch (p_cur[i].type) {
3297 case RIL_HARDWARE_CONFIG_MODEM: {
3298 writeStringToParcel(p, p_cur[i].uuid);
3299 p.writeInt32((int)p_cur[i].state);
3300 p.writeInt32(p_cur[i].cfg.modem.rat);
3301 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3302 p.writeInt32(p_cur[i].cfg.modem.maxData);
3303 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3304
3305 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3306 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3307 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3308 break;
3309 }
3310 case RIL_HARDWARE_CONFIG_SIM: {
3311 writeStringToParcel(p, p_cur[i].uuid);
3312 p.writeInt32((int)p_cur[i].state);
3313 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3314
3315 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3316 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3317 break;
3318 }
3319 }
3320 }
3321 removeLastChar;
3322 closeResponse;
3323 return 0;
3324}
3325
Wink Saville8b4e4f72014-10-17 15:01:45 -07003326static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3327 if (response == NULL) {
3328 RLOGE("invalid response: NULL");
3329 return RIL_ERRNO_INVALID_RESPONSE;
3330 }
3331
3332 if (responselen != sizeof (RIL_RadioCapability) ) {
3333 RLOGE("invalid response length was %d expected %d",
3334 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3335 return RIL_ERRNO_INVALID_RESPONSE;
3336 }
3337
3338 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3339 p.writeInt32(p_cur->version);
3340 p.writeInt32(p_cur->session);
3341 p.writeInt32(p_cur->phase);
3342 p.writeInt32(p_cur->rat);
3343 writeStringToParcel(p, p_cur->logicalModemUuid);
3344 p.writeInt32(p_cur->status);
3345
3346 startResponse;
3347 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Legler Wu8caf06f2014-10-29 14:02:14 +08003348 rat=%s,logicalModemUuid=%s,status=%d]",
Wink Saville8b4e4f72014-10-17 15:01:45 -07003349 printBuf,
3350 p_cur->version,
3351 p_cur->session,
3352 p_cur->phase,
3353 p_cur->rat,
Legler Wu8caf06f2014-10-29 14:02:14 +08003354 p_cur->logicalModemUuid,
Wink Saville8b4e4f72014-10-17 15:01:45 -07003355 p_cur->status);
3356 closeResponse;
3357 return 0;
3358}
3359
Amit Mahajan54563d32014-11-22 00:54:49 +00003360static int responseSSData(Parcel &p, void *response, size_t responselen) {
3361 RLOGD("In responseSSData");
3362 int num;
3363
3364 if (response == NULL && responselen != 0) {
3365 RLOGE("invalid response length was %d expected %d",
3366 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3367 return RIL_ERRNO_INVALID_RESPONSE;
3368 }
3369
3370 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3371 RLOGE("invalid response length %d, expected %d",
3372 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3373 return RIL_ERRNO_INVALID_RESPONSE;
3374 }
3375
3376 startResponse;
3377 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3378 p.writeInt32(p_cur->serviceType);
3379 p.writeInt32(p_cur->requestType);
3380 p.writeInt32(p_cur->teleserviceType);
3381 p.writeInt32(p_cur->serviceClass);
3382 p.writeInt32(p_cur->result);
3383
3384 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3385 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3386 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3387 RLOGE("numValidIndexes is greater than max value %d, "
3388 "truncating it to max value", NUM_SERVICE_CLASSES);
3389 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3390 }
3391 /* number of call info's */
3392 p.writeInt32(p_cur->cfData.numValidIndexes);
3393
3394 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3395 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3396
3397 p.writeInt32(cf.status);
3398 p.writeInt32(cf.reason);
3399 p.writeInt32(cf.serviceClass);
3400 p.writeInt32(cf.toa);
3401 writeStringToParcel(p, cf.number);
3402 p.writeInt32(cf.timeSeconds);
3403 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3404 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3405 (char*)cf.number, cf.timeSeconds);
3406 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3407 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3408 }
3409 } else {
3410 p.writeInt32 (SS_INFO_MAX);
3411
3412 /* each int*/
3413 for (int i = 0; i < SS_INFO_MAX; i++) {
3414 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3415 RLOGD("Data: %d",p_cur->ssInfo[i]);
3416 p.writeInt32(p_cur->ssInfo[i]);
3417 }
3418 }
3419 removeLastChar;
3420 closeResponse;
3421
3422 return 0;
3423}
3424
3425static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3426 if ((reqType == SS_INTERROGATION) &&
3427 (serType == SS_CFU ||
3428 serType == SS_CF_BUSY ||
3429 serType == SS_CF_NO_REPLY ||
3430 serType == SS_CF_NOT_REACHABLE ||
3431 serType == SS_CF_ALL ||
3432 serType == SS_CF_ALL_CONDITIONAL)) {
3433 return true;
3434 }
3435 return false;
3436}
3437
Wink Saville3d54e742009-05-18 18:00:44 -07003438static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003439 int ret;
3440 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3441 /* trigger event loop to wakeup. No reason to do this,
3442 * if we're in the event loop thread */
3443 do {
3444 ret = write (s_fdWakeupWrite, " ", 1);
3445 } while (ret < 0 && errno == EINTR);
3446 }
3447}
3448
Wink Saville3d54e742009-05-18 18:00:44 -07003449static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003450 ril_event_add(ev);
3451 triggerEvLoop();
3452}
3453
Wink Savillefd729372011-02-22 16:19:39 -08003454static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3455 p.writeInt32(num_apps);
3456 startResponse;
3457 for (int i = 0; i < num_apps; i++) {
3458 p.writeInt32(appStatus[i].app_type);
3459 p.writeInt32(appStatus[i].app_state);
3460 p.writeInt32(appStatus[i].perso_substate);
3461 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3462 writeStringToParcel(p, (const char*)
3463 (appStatus[i].app_label_ptr));
3464 p.writeInt32(appStatus[i].pin1_replaced);
3465 p.writeInt32(appStatus[i].pin1);
3466 p.writeInt32(appStatus[i].pin2);
3467 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3468 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3469 printBuf,
3470 appStatus[i].app_type,
3471 appStatus[i].app_state,
3472 appStatus[i].perso_substate,
3473 appStatus[i].aid_ptr,
3474 appStatus[i].app_label_ptr,
3475 appStatus[i].pin1_replaced,
3476 appStatus[i].pin1,
3477 appStatus[i].pin2);
3478 }
3479 closeResponse;
3480}
3481
Wink Savillef4c4d362009-04-02 01:37:03 -07003482static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3483 int i;
3484
3485 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003486 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003487 return RIL_ERRNO_INVALID_RESPONSE;
3488 }
3489
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003490 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003491 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003492
Wink Savillefd729372011-02-22 16:19:39 -08003493 p.writeInt32(p_cur->card_state);
3494 p.writeInt32(p_cur->universal_pin_state);
3495 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3496 p.writeInt32(p_cur->cdma_subscription_app_index);
3497 p.writeInt32(p_cur->ims_subscription_app_index);
3498
3499 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003500 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003501 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3502
3503 p.writeInt32(p_cur->card_state);
3504 p.writeInt32(p_cur->universal_pin_state);
3505 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3506 p.writeInt32(p_cur->cdma_subscription_app_index);
3507 p.writeInt32(-1);
3508
3509 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003510 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003511 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003512 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003513 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003514
3515 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003516}
Wink Savillef4c4d362009-04-02 01:37:03 -07003517
Wink Savillea592eeb2009-05-22 13:26:36 -07003518static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3519 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003520 p.writeInt32(num);
3521
Wink Savillef4c4d362009-04-02 01:37:03 -07003522 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003523 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3524 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3525 for (int i = 0; i < num; i++) {
3526 p.writeInt32(p_cur[i]->fromServiceId);
3527 p.writeInt32(p_cur[i]->toServiceId);
3528 p.writeInt32(p_cur[i]->fromCodeScheme);
3529 p.writeInt32(p_cur[i]->toCodeScheme);
3530 p.writeInt32(p_cur[i]->selected);
3531
3532 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3533 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3534 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3535 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3536 p_cur[i]->selected);
3537 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003538 closeResponse;
3539
3540 return 0;
3541}
3542
Wink Savillea592eeb2009-05-22 13:26:36 -07003543static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3544 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3545 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003546
Wink Savillea592eeb2009-05-22 13:26:36 -07003547 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3548 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003549
3550 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003551 for (int i = 0 ; i < num ; i++ ) {
3552 p.writeInt32(p_cur[i]->service_category);
3553 p.writeInt32(p_cur[i]->language);
3554 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003555
Wink Savillea592eeb2009-05-22 13:26:36 -07003556 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3557 selected =%d], ",
3558 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3559 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003560 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003561 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003562
Wink Savillef4c4d362009-04-02 01:37:03 -07003563 return 0;
3564}
3565
3566static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3567 int num;
3568 int digitCount;
3569 int digitLimit;
3570 uint8_t uct;
3571 void* dest;
3572
Wink Saville8eb2a122012-11-19 16:05:13 -08003573 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003574
Wink Savillef4c4d362009-04-02 01:37:03 -07003575 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003576 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003577 return RIL_ERRNO_INVALID_RESPONSE;
3578 }
3579
Wink Savillef5903df2009-04-24 11:54:14 -07003580 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003581 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003582 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003583 return RIL_ERRNO_INVALID_RESPONSE;
3584 }
3585
3586 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3587 p.writeInt32(p_cur->uTeleserviceID);
3588 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3589 p.writeInt32(p_cur->uServicecategory);
3590 p.writeInt32(p_cur->sAddress.digit_mode);
3591 p.writeInt32(p_cur->sAddress.number_mode);
3592 p.writeInt32(p_cur->sAddress.number_type);
3593 p.writeInt32(p_cur->sAddress.number_plan);
3594 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3595 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3596 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3597 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3598 }
3599
3600 p.writeInt32(p_cur->sSubAddress.subaddressType);
3601 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3602 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3603 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3604 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3605 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3606 }
3607
3608 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3609 p.writeInt32(p_cur->uBearerDataLen);
3610 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3611 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3612 }
3613
3614 startResponse;
3615 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003616 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003617 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3618 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3619 closeResponse;
3620
3621 return 0;
3622}
3623
Wink Savillec29360a2014-07-13 05:17:28 -07003624static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3625{
3626 int num = responselen / sizeof(RIL_DcRtInfo);
3627 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
Amit Mahajan52500162014-07-29 17:36:48 -07003628 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
Wink Savillec29360a2014-07-13 05:17:28 -07003629 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3630 return RIL_ERRNO_INVALID_RESPONSE;
3631 }
3632
3633 startResponse;
3634 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3635 p.writeInt64(pDcRtInfo->time);
3636 p.writeInt32(pDcRtInfo->powerState);
3637 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3638 pDcRtInfo->time,
3639 pDcRtInfo->powerState);
3640 closeResponse;
3641
3642 return 0;
3643}
3644
fengluf7408292015-04-14 14:53:55 -07003645static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3646 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3647 if (response == NULL) {
3648 RLOGE("invalid response: NULL");
3649 }
3650 else {
3651 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3652 sizeof(RIL_LceStatusInfo), responselen);
3653 }
3654 return RIL_ERRNO_INVALID_RESPONSE;
3655 }
3656
3657 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3658 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3659 p.writeInt32(p_cur->actual_interval_ms);
3660
3661 startResponse;
3662 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3663 p_cur->lce_status, p_cur->actual_interval_ms);
3664 closeResponse;
3665
3666 return 0;
3667}
3668
3669static int responseLceData(Parcel &p, void *response, size_t responselen) {
3670 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3671 if (response == NULL) {
3672 RLOGE("invalid response: NULL");
3673 }
3674 else {
3675 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3676 sizeof(RIL_LceDataInfo), responselen);
3677 }
3678 return RIL_ERRNO_INVALID_RESPONSE;
3679 }
3680
3681 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3682 p.writeInt32(p_cur->last_hop_capacity_kbps);
3683
3684 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3685 p.write((void *)&(p_cur->confidence_level), 1);
3686 p.write((void *)&(p_cur->lce_suspended), 1);
3687
3688 startResponse;
3689 appendPrintBuf("LCE info received: capacity %d confidence level %d
3690 and suspended %d",
3691 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3692 p_cur->lce_suspended);
3693 closeResponse;
3694
3695 return 0;
3696}
3697
Prerepa Viswanadham73157492015-05-28 00:37:32 -07003698static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3699 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3700 if (response == NULL) {
3701 RLOGE("invalid response: NULL");
3702 }
3703 else {
3704 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3705 sizeof(RIL_ActivityStatsInfo), responselen);
3706 }
3707 return RIL_ERRNO_INVALID_RESPONSE;
3708 }
3709
3710 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3711 p.writeInt32(p_cur->sleep_mode_time_ms);
3712 p.writeInt32(p_cur->idle_mode_time_ms);
3713 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3714 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3715 }
3716 p.writeInt32(p_cur->rx_mode_time_ms);
3717
3718 startResponse;
3719 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
3720 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3721 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3722 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3723 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3724 closeResponse;
3725
3726 return 0;
3727}
3728
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003729/**
3730 * A write on the wakeup fd is done just to pop us out of select()
3731 * We empty the buffer here and then ril_event will reset the timers on the
3732 * way back down
3733 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003734static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003735 char buff[16];
3736 int ret;
3737
Wink Saville8eb2a122012-11-19 16:05:13 -08003738 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003739
3740 /* empty our wakeup socket out */
3741 do {
3742 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003743 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003744}
3745
Etan Cohend3652192014-06-20 08:28:44 -07003746static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003747 int ret;
3748 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003749 /* Hook for current context
3750 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3751 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3752 /* pendingRequestsHook refer to &s_pendingRequests */
3753 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003754
Etan Cohend3652192014-06-20 08:28:44 -07003755#if (SIM_COUNT >= 2)
3756 if (socket_id == RIL_SOCKET_2) {
3757 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3758 pendingRequestsHook = &s_pendingRequests_socket2;
3759 }
3760#if (SIM_COUNT >= 3)
3761 else if (socket_id == RIL_SOCKET_3) {
3762 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3763 pendingRequestsHook = &s_pendingRequests_socket3;
3764 }
3765#endif
3766#if (SIM_COUNT >= 4)
3767 else if (socket_id == RIL_SOCKET_4) {
3768 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3769 pendingRequestsHook = &s_pendingRequests_socket4;
3770 }
3771#endif
3772#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003773 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003774 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003775 assert (ret == 0);
3776
Etan Cohend3652192014-06-20 08:28:44 -07003777 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003778
Etan Cohend3652192014-06-20 08:28:44 -07003779 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003780 ; p_cur != NULL
3781 ; p_cur = p_cur->p_next
3782 ) {
3783 p_cur->cancelled = 1;
3784 }
3785
Etan Cohend3652192014-06-20 08:28:44 -07003786 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003787 assert (ret == 0);
3788}
3789
Wink Savillef4c4d362009-04-02 01:37:03 -07003790static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003791 RecordStream *p_rs;
3792 void *p_record;
3793 size_t recordlen;
3794 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003795 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003796
Etan Cohend3652192014-06-20 08:28:44 -07003797 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003798
Etan Cohend3652192014-06-20 08:28:44 -07003799 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003800
3801 for (;;) {
3802 /* loop until EAGAIN/EINTR, end of stream, or other error */
3803 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3804
3805 if (ret == 0 && p_record == NULL) {
3806 /* end-of-stream */
3807 break;
3808 } else if (ret < 0) {
3809 break;
3810 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003811 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003812 }
3813 }
3814
3815 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3816 /* fatal error or end-of-stream */
3817 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003818 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003820 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003821 }
Wink Saville7f856802009-06-09 10:23:37 -07003822
Etan Cohend3652192014-06-20 08:28:44 -07003823 close(fd);
3824 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003825
Etan Cohend3652192014-06-20 08:28:44 -07003826 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003827
3828 record_stream_free(p_rs);
3829
3830 /* start listening for new connections again */
3831 rilEventAddWakeup(&s_listen_event);
3832
Etan Cohend3652192014-06-20 08:28:44 -07003833 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003834 }
3835}
3836
3837
Etan Cohend3652192014-06-20 08:28:44 -07003838static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003839 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003840 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003841 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3842 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003843
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003844 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003845 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3846 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003847
3848 // Send last NITZ time data, in case it was missed
3849 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003850 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003851
3852 free(s_lastNITZTimeData);
3853 s_lastNITZTimeData = NULL;
3854 }
3855
3856 // Get version string
3857 if (s_callbacks.getVersion != NULL) {
3858 const char *version;
3859 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003860 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003861
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003862 property_set(PROPERTY_RIL_IMPL, version);
3863 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003864 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003865 property_set(PROPERTY_RIL_IMPL, "unavailable");
3866 }
3867
3868}
3869
Wink Savillef4c4d362009-04-02 01:37:03 -07003870static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003871 int ret;
3872 int err;
3873 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003874 int fdCommand = -1;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003875 char* processName;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003876 RecordStream *p_rs;
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003877 MySocketListenParam* listenParam;
3878 RilSocket *sapSocket = NULL;
3879 socketClient *sClient = NULL;
3880
Etan Cohend3652192014-06-20 08:28:44 -07003881 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003882
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003883 if(RIL_SAP_SOCKET == p_info->type) {
3884 listenParam = (MySocketListenParam *)param;
3885 sapSocket = listenParam->socket;
3886 }
3887
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003888 struct sockaddr_un peeraddr;
3889 socklen_t socklen = sizeof (peeraddr);
3890
3891 struct ucred creds;
3892 socklen_t szCreds = sizeof(creds);
3893
3894 struct passwd *pwd = NULL;
3895
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003896 if(NULL == sapSocket) {
3897 assert (*p_info->fdCommand < 0);
3898 assert (fd == *p_info->fdListen);
3899 processName = PHONE_PROCESS;
3900 } else {
3901 assert (sapSocket->commandFd < 0);
3902 assert (fd == sapSocket->listenFd);
3903 processName = BLUETOOTH_PROCESS;
3904 }
3905
Wink Saville7f856802009-06-09 10:23:37 -07003906
Etan Cohend3652192014-06-20 08:28:44 -07003907 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003908
Etan Cohend3652192014-06-20 08:28:44 -07003909 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003910 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003911 /* start listening for new connections again */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003912 if(NULL == sapSocket) {
3913 rilEventAddWakeup(p_info->listen_event);
3914 } else {
3915 rilEventAddWakeup(sapSocket->getListenEvent());
3916 }
Etan Cohend3652192014-06-20 08:28:44 -07003917 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003918 }
3919
3920 /* check the credential of the other side and only accept socket from
3921 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003922 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003923 errno = 0;
3924 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003925
Etan Cohend3652192014-06-20 08:28:44 -07003926 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003927
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003928 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003929 errno = 0;
3930 pwd = getpwuid(creds.uid);
3931 if (pwd != NULL) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003932 if (strcmp(pwd->pw_name, processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003933 is_phone_socket = 1;
3934 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003935 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003936 }
3937 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003938 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003939 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003940 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003941 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003942 }
3943
Etan Cohend3652192014-06-20 08:28:44 -07003944 if (!is_phone_socket) {
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003945 RLOGE("RILD must accept socket from %s", processName);
Wink Saville7f856802009-06-09 10:23:37 -07003946
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003947 close(fdCommand);
3948 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003949
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003950 if(NULL == sapSocket) {
3951 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003952
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003953 /* start listening for new connections again */
3954 rilEventAddWakeup(p_info->listen_event);
3955 } else {
3956 sapSocket->onCommandsSocketClosed();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003957
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003958 /* start listening for new connections again */
3959 rilEventAddWakeup(sapSocket->getListenEvent());
3960 }
3961
3962 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003963 }
3964
Etan Cohend3652192014-06-20 08:28:44 -07003965 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003966
3967 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003968 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003969 }
3970
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003971 if(NULL == sapSocket) {
3972 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003973
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003974 p_info->fdCommand = fdCommand;
3975 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
3976 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003977
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003978 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Etan Cohend3652192014-06-20 08:28:44 -07003979 p_info->processCommandsCallback, p_info);
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003980 rilEventAddWakeup (p_info->commands_event);
Etan Cohend3652192014-06-20 08:28:44 -07003981
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003982 onNewCommandConnect(p_info->socket_id);
3983 } else {
3984 RLOGI("libril: new connection");
Etan Cohend3652192014-06-20 08:28:44 -07003985
Dheeraj Shetty27976c42014-07-02 21:27:57 +02003986 sapSocket->setCommandFd(fdCommand);
3987 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
3988 sClient = new socketClient(sapSocket,p_rs);
3989 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
3990 sapSocket->getCommandCb(), sClient);
3991
3992 rilEventAddWakeup(sapSocket->getCallbackEvent());
3993 sapSocket->onNewCommandConnect();
3994 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003995}
3996
3997static void freeDebugCallbackArgs(int number, char **args) {
3998 for (int i = 0; i < number; i++) {
3999 if (args[i] != NULL) {
4000 free(args[i]);
4001 }
4002 }
4003 free(args);
4004}
4005
Wink Savillef4c4d362009-04-02 01:37:03 -07004006static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004007 int acceptFD, option;
4008 struct sockaddr_un peeraddr;
4009 socklen_t socklen = sizeof (peeraddr);
4010 int data;
4011 unsigned int qxdm_data[6];
4012 const char *deactData[1] = {"1"};
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004013 RIL_Dial dialData;
4014 int hangupData[1] = {1};
4015 int number;
4016 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07004017 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Sanket Padawe72e31ab2017-07-13 14:19:28 -07004018 int MAX_DIAL_ADDRESS = 128;
Etan Cohend3652192014-06-20 08:28:44 -07004019 int sim_id = 0;
4020
4021 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004022
4023 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4024
4025 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004026 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004027 return;
4028 }
4029
4030 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004031 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004032 return;
4033 }
4034 args = (char **) malloc(sizeof(char*) * number);
4035
4036 for (int i = 0; i < number; i++) {
4037 int len;
4038 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004039 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004040 freeDebugCallbackArgs(i, args);
4041 return;
4042 }
4043 // +1 for null-term
4044 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07004045 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07004046 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004047 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004048 freeDebugCallbackArgs(i, args);
4049 return;
4050 }
4051 char * buf = args[i];
4052 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004053 if ((i+1) == number) {
4054 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4055 sim_id = atoi(args[i]);
4056 switch (sim_id) {
4057 case 0:
4058 socket_id = RIL_SOCKET_1;
4059 break;
4060 #if (SIM_COUNT >= 2)
4061 case 1:
4062 socket_id = RIL_SOCKET_2;
4063 break;
4064 #endif
4065 #if (SIM_COUNT >= 3)
4066 case 2:
4067 socket_id = RIL_SOCKET_3;
4068 break;
4069 #endif
4070 #if (SIM_COUNT >= 4)
4071 case 3:
4072 socket_id = RIL_SOCKET_4;
4073 break;
4074 #endif
4075 default:
4076 socket_id = RIL_SOCKET_1;
4077 break;
4078 }
4079 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004080 }
4081
4082 switch (atoi(args[0])) {
4083 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08004084 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07004085 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004086 break;
4087 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08004088 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004089 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004090 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004091 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07004092 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
4093 close(s_ril_param_socket.fdCommand);
4094 s_ril_param_socket.fdCommand = -1;
4095 }
4096 #if (SIM_COUNT == 2)
4097 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4098 close(s_ril_param_socket2.fdCommand);
4099 s_ril_param_socket2.fdCommand = -1;
4100 }
4101 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004102 break;
4103 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08004104 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07004105 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004106 break;
4107 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08004108 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07004109 qxdm_data[0] = 65536; // head.func_tag
4110 qxdm_data[1] = 16; // head.len
4111 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4112 qxdm_data[3] = 32; // log_file_size: 32megabytes
4113 qxdm_data[4] = 0; // log_mask
4114 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07004115 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004116 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004117 break;
4118 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08004119 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004120 qxdm_data[0] = 65536;
4121 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07004122 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004123 qxdm_data[3] = 32;
4124 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07004125 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004126 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07004127 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004128 break;
4129 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08004130 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004131 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07004132 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004133 sleep(2);
4134 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07004135 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004136 break;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004137 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08004138 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07004139 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07004140 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004141 break;
4142 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08004143 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004144 dialData.clir = 0;
Sanket Padawe72e31ab2017-07-13 14:19:28 -07004145 if (strlen(args[1]) > MAX_DIAL_ADDRESS) {
4146 RLOGE("Debug port: Error calling Dial");
4147 freeDebugCallbackArgs(number, args);
4148 close(acceptFD);
4149 return;
4150 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004151 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07004152 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004153 break;
4154 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08004155 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07004156 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004157 break;
4158 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08004159 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07004160 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07004161 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004162 break;
4163 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004164 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004165 break;
4166 }
4167 freeDebugCallbackArgs(number, args);
4168 close(acceptFD);
4169}
4170
4171
Wink Savillef4c4d362009-04-02 01:37:03 -07004172static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004173 UserCallbackInfo *p_info;
4174
4175 p_info = (UserCallbackInfo *)param;
4176
4177 p_info->p_callback(p_info->userParam);
4178
4179
4180 // FIXME generalize this...there should be a cancel mechanism
4181 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4182 s_last_wake_timeout_info = NULL;
4183 }
4184
4185 free(p_info);
4186}
4187
4188
4189static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07004190eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004191 int ret;
4192 int filedes[2];
4193
4194 ril_event_init();
4195
4196 pthread_mutex_lock(&s_startupMutex);
4197
4198 s_started = 1;
4199 pthread_cond_broadcast(&s_startupCond);
4200
4201 pthread_mutex_unlock(&s_startupMutex);
4202
4203 ret = pipe(filedes);
4204
4205 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004206 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004207 return NULL;
4208 }
4209
4210 s_fdWakeupRead = filedes[0];
4211 s_fdWakeupWrite = filedes[1];
4212
4213 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4214
4215 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4216 processWakeupCallback, NULL);
4217
4218 rilEventAddWakeup (&s_wakeupfd_event);
4219
4220 // Only returns on error
4221 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08004222 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05004223 // kill self to restart on error
4224 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004225
4226 return NULL;
4227}
4228
Wink Saville7f856802009-06-09 10:23:37 -07004229extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004230RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004231 /* spin up eventLoop thread and wait for it to get started */
4232 s_started = 0;
4233 pthread_mutex_lock(&s_startupMutex);
4234
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004235 pthread_attr_t attr;
4236 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07004237 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004238
Elliott Hughesfd81e712014-01-06 12:46:02 -08004239 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4240 if (result != 0) {
4241 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004242 goto done;
4243 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004244
4245 while (s_started == 0) {
4246 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4247 }
4248
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08004249done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004250 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004251}
4252
4253// Used for testing purpose only.
4254extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4255 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4256}
4257
Etan Cohend3652192014-06-20 08:28:44 -07004258static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4259 int fdListen = -1;
4260 int ret;
4261 char socket_name[10];
4262
4263 memset(socket_name, 0, sizeof(char)*10);
4264
4265 switch(socket_id) {
4266 case RIL_SOCKET_1:
4267 strncpy(socket_name, RIL_getRilSocketName(), 9);
4268 break;
4269 #if (SIM_COUNT >= 2)
4270 case RIL_SOCKET_2:
4271 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4272 break;
4273 #endif
4274 #if (SIM_COUNT >= 3)
4275 case RIL_SOCKET_3:
4276 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4277 break;
4278 #endif
4279 #if (SIM_COUNT >= 4)
4280 case RIL_SOCKET_4:
4281 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4282 break;
4283 #endif
4284 default:
4285 RLOGE("Socket id is wrong!!");
4286 return;
4287 }
4288
4289 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4290
4291 fdListen = android_get_control_socket(socket_name);
4292 if (fdListen < 0) {
4293 RLOGE("Failed to get socket %s", socket_name);
4294 exit(-1);
4295 }
4296
4297 ret = listen(fdListen, 4);
4298
4299 if (ret < 0) {
4300 RLOGE("Failed to listen on control socket '%d': %s",
4301 fdListen, strerror(errno));
4302 exit(-1);
4303 }
4304 socket_listen_p->fdListen = fdListen;
4305
4306 /* note: non-persistent so we can accept only one connection at a time */
4307 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4308 listenCallback, socket_listen_p);
4309
4310 rilEventAddWakeup (socket_listen_p->listen_event);
4311}
4312
Wink Saville7f856802009-06-09 10:23:37 -07004313extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004314RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004315 int ret;
4316 int flags;
4317
Etan Cohend3652192014-06-20 08:28:44 -07004318 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4319
Wink Saville43808972011-01-13 17:39:51 -08004320 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004321 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004322 return;
4323 }
Wink Saville43808972011-01-13 17:39:51 -08004324 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004325 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004326 callbacks->version, RIL_VERSION_MIN);
4327 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07004328 }
Wink Saville43808972011-01-13 17:39:51 -08004329 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004330 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08004331 callbacks->version, RIL_VERSION);
4332 return;
4333 }
Wink Saville8eb2a122012-11-19 16:05:13 -08004334 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004335
4336 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004337 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004338 "Subsequent call ignored");
4339 return;
4340 }
4341
4342 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4343
Etan Cohend3652192014-06-20 08:28:44 -07004344 /* Initialize socket1 parameters */
4345 s_ril_param_socket = {
4346 RIL_SOCKET_1, /* socket_id */
4347 -1, /* fdListen */
4348 -1, /* fdCommand */
4349 PHONE_PROCESS, /* processName */
4350 &s_commands_event, /* commands_event */
4351 &s_listen_event, /* listen_event */
4352 processCommandsCallback, /* processCommandsCallback */
4353 NULL /* p_rs */
4354 };
4355
4356#if (SIM_COUNT >= 2)
4357 s_ril_param_socket2 = {
4358 RIL_SOCKET_2, /* socket_id */
4359 -1, /* fdListen */
4360 -1, /* fdCommand */
4361 PHONE_PROCESS, /* processName */
4362 &s_commands_event_socket2, /* commands_event */
4363 &s_listen_event_socket2, /* listen_event */
4364 processCommandsCallback, /* processCommandsCallback */
4365 NULL /* p_rs */
4366 };
4367#endif
4368
4369#if (SIM_COUNT >= 3)
4370 s_ril_param_socket3 = {
4371 RIL_SOCKET_3, /* socket_id */
4372 -1, /* fdListen */
4373 -1, /* fdCommand */
4374 PHONE_PROCESS, /* processName */
4375 &s_commands_event_socket3, /* commands_event */
4376 &s_listen_event_socket3, /* listen_event */
4377 processCommandsCallback, /* processCommandsCallback */
4378 NULL /* p_rs */
4379 };
4380#endif
4381
4382#if (SIM_COUNT >= 4)
4383 s_ril_param_socket4 = {
4384 RIL_SOCKET_4, /* socket_id */
4385 -1, /* fdListen */
4386 -1, /* fdCommand */
4387 PHONE_PROCESS, /* processName */
4388 &s_commands_event_socket4, /* commands_event */
4389 &s_listen_event_socket4, /* listen_event */
4390 processCommandsCallback, /* processCommandsCallback */
4391 NULL /* p_rs */
4392 };
4393#endif
4394
4395
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004396 s_registerCalled = 1;
4397
Etan Cohend3652192014-06-20 08:28:44 -07004398 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004399 // Little self-check
4400
Wink Savillef4c4d362009-04-02 01:37:03 -07004401 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004402 assert(i == s_commands[i].requestNumber);
4403 }
4404
Wink Savillef4c4d362009-04-02 01:37:03 -07004405 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07004406 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004407 == s_unsolResponses[i].requestNumber);
4408 }
4409
4410 // New rild impl calls RIL_startEventLoop() first
4411 // old standalone impl wants it here.
4412
4413 if (s_started == 0) {
4414 RIL_startEventLoop();
4415 }
4416
Etan Cohend3652192014-06-20 08:28:44 -07004417 // start listen socket1
4418 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004419
Etan Cohend3652192014-06-20 08:28:44 -07004420#if (SIM_COUNT >= 2)
4421 // start listen socket2
4422 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4423#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004424
Etan Cohend3652192014-06-20 08:28:44 -07004425#if (SIM_COUNT >= 3)
4426 // start listen socket3
4427 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4428#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004429
Etan Cohend3652192014-06-20 08:28:44 -07004430#if (SIM_COUNT >= 4)
4431 // start listen socket4
4432 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4433#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004434
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004435
4436#if 1
4437 // start debug interface socket
4438
Etan Cohend3652192014-06-20 08:28:44 -07004439 char *inst = NULL;
4440 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4441 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4442 }
4443
4444 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4445 if (inst != NULL) {
Nick Kralevichc52e45e2015-02-08 07:54:16 -08004446 strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
Etan Cohend3652192014-06-20 08:28:44 -07004447 }
4448
4449 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004450 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004451 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004452 exit(-1);
4453 }
4454
4455 ret = listen(s_fdDebug, 4);
4456
4457 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004458 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004459 s_fdDebug, strerror(errno));
4460 exit(-1);
4461 }
4462
4463 ril_event_set (&s_debug_event, s_fdDebug, true,
4464 debugCallback, NULL);
4465
4466 rilEventAddWakeup (&s_debug_event);
4467#endif
4468
4469}
4470
Dheeraj Shetty27976c42014-07-02 21:27:57 +02004471extern "C" void
4472RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4473
4474 RIL_RadioFunctions* UimFuncs = NULL;
4475
4476 if(Init) {
4477 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4478
4479 switch(socketType) {
4480 case RIL_SAP_SOCKET:
4481 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4482
4483#if (SIM_COUNT >= 2)
4484 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4485#endif
4486
4487#if (SIM_COUNT >= 3)
4488 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4489#endif
4490
4491#if (SIM_COUNT >= 4)
4492 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4493#endif
4494 }
4495 }
4496}
4497
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004498static int
Wink Savillef4c4d362009-04-02 01:37:03 -07004499checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004500 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07004501 /* Hook for current context
4502 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4503 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4504 /* pendingRequestsHook refer to &s_pendingRequests */
4505 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07004506
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004507 if (pRI == NULL) {
4508 return 0;
4509 }
4510
Etan Cohend3652192014-06-20 08:28:44 -07004511#if (SIM_COUNT >= 2)
4512 if (pRI->socket_id == RIL_SOCKET_2) {
4513 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4514 pendingRequestsHook = &s_pendingRequests_socket2;
4515 }
4516#if (SIM_COUNT >= 3)
4517 if (pRI->socket_id == RIL_SOCKET_3) {
4518 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4519 pendingRequestsHook = &s_pendingRequests_socket3;
4520 }
4521#endif
4522#if (SIM_COUNT >= 4)
4523 if (pRI->socket_id == RIL_SOCKET_4) {
4524 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4525 pendingRequestsHook = &s_pendingRequests_socket4;
4526 }
4527#endif
4528#endif
4529 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004530
Etan Cohend3652192014-06-20 08:28:44 -07004531 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07004532 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004533 ; ppCur = &((*ppCur)->p_next)
4534 ) {
4535 if (pRI == *ppCur) {
4536 ret = 1;
4537
4538 *ppCur = (*ppCur)->p_next;
4539 break;
4540 }
4541 }
4542
Etan Cohend3652192014-06-20 08:28:44 -07004543 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004544
4545 return ret;
4546}
4547
4548
4549extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07004550RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004551 RequestInfo *pRI;
4552 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07004553 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004554 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07004555 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004556
4557 pRI = (RequestInfo *)t;
4558
Jayachandran C6c607592014-08-04 15:48:01 -07004559 if (!checkAndDequeueRequestInfo(pRI)) {
4560 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
4561 return;
4562 }
4563
Etan Cohend3652192014-06-20 08:28:44 -07004564 socket_id = pRI->socket_id;
4565#if (SIM_COUNT >= 2)
4566 if (socket_id == RIL_SOCKET_2) {
4567 fd = s_ril_param_socket2.fdCommand;
4568 }
4569#if (SIM_COUNT >= 3)
4570 if (socket_id == RIL_SOCKET_3) {
4571 fd = s_ril_param_socket3.fdCommand;
4572 }
4573#endif
4574#if (SIM_COUNT >= 4)
4575 if (socket_id == RIL_SOCKET_4) {
4576 fd = s_ril_param_socket4.fdCommand;
4577 }
4578#endif
4579#endif
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004580#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004581 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004582#endif
Etan Cohend3652192014-06-20 08:28:44 -07004583
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004584 if (pRI->local > 0) {
4585 // Locally issued command...void only!
4586 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08004587 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004588
4589 goto done;
4590 }
4591
4592 appendPrintBuf("[%04d]< %s",
4593 pRI->token, requestToString(pRI->pCI->requestNumber));
4594
4595 if (pRI->cancelled == 0) {
4596 Parcel p;
4597
4598 p.writeInt32 (RESPONSE_SOLICITED);
4599 p.writeInt32 (pRI->token);
4600 errorOffset = p.dataPosition();
4601
4602 p.writeInt32 (e);
4603
johnwangb2a61842009-06-02 14:55:45 -07004604 if (response != NULL) {
4605 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004606 ret = pRI->pCI->responseFunction(p, response, responselen);
4607
4608 /* if an error occurred, rewind and mark it */
4609 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07004610 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004611 p.setDataPosition(errorOffset);
4612 p.writeInt32 (ret);
4613 }
johnwangb2a61842009-06-02 14:55:45 -07004614 }
4615
4616 if (e != RIL_E_SUCCESS) {
4617 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004618 }
4619
Etan Cohend3652192014-06-20 08:28:44 -07004620 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004621 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004622 }
Etan Cohend3652192014-06-20 08:28:44 -07004623 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004624 }
4625
4626done:
4627 free(pRI);
4628}
4629
4630
4631static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004632grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004633 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4634}
4635
4636static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004637releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004638 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4639}
4640
4641/**
4642 * Timer callback to put us back to sleep before the default timeout
4643 */
4644static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004645wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004646 // We're using "param != NULL" as a cancellation mechanism
4647 if (param == NULL) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004648 releaseWakeLock();
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004649 }
4650}
4651
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004652static int
4653decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4654 switch (radioState) {
4655 case RADIO_STATE_SIM_NOT_READY:
4656 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4657 case RADIO_STATE_SIM_READY:
4658 return RADIO_TECH_UMTS;
4659
4660 case RADIO_STATE_RUIM_NOT_READY:
4661 case RADIO_STATE_RUIM_READY:
4662 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4663 case RADIO_STATE_NV_NOT_READY:
4664 case RADIO_STATE_NV_READY:
4665 return RADIO_TECH_1xRTT;
4666
4667 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004668 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004669 return -1;
4670 }
4671}
4672
4673static int
4674decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4675 switch (radioState) {
4676 case RADIO_STATE_SIM_NOT_READY:
4677 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4678 case RADIO_STATE_SIM_READY:
4679 case RADIO_STATE_RUIM_NOT_READY:
4680 case RADIO_STATE_RUIM_READY:
4681 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4682 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4683
4684 case RADIO_STATE_NV_NOT_READY:
4685 case RADIO_STATE_NV_READY:
4686 return CDMA_SUBSCRIPTION_SOURCE_NV;
4687
4688 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004689 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004690 return -1;
4691 }
4692}
4693
4694static int
4695decodeSimStatus (RIL_RadioState radioState) {
4696 switch (radioState) {
4697 case RADIO_STATE_SIM_NOT_READY:
4698 case RADIO_STATE_RUIM_NOT_READY:
4699 case RADIO_STATE_NV_NOT_READY:
4700 case RADIO_STATE_NV_READY:
4701 return -1;
4702 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4703 case RADIO_STATE_SIM_READY:
4704 case RADIO_STATE_RUIM_READY:
4705 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4706 return radioState;
4707 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004708 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004709 return -1;
4710 }
4711}
4712
4713static bool is3gpp2(int radioTech) {
4714 switch (radioTech) {
4715 case RADIO_TECH_IS95A:
4716 case RADIO_TECH_IS95B:
4717 case RADIO_TECH_1xRTT:
4718 case RADIO_TECH_EVDO_0:
4719 case RADIO_TECH_EVDO_A:
4720 case RADIO_TECH_EVDO_B:
4721 case RADIO_TECH_EHRPD:
4722 return true;
4723 default:
4724 return false;
4725 }
4726}
4727
4728/* If RIL sends SIM states or RUIM states, store the voice radio
4729 * technology and subscription source information so that they can be
4730 * returned when telephony framework requests them
4731 */
4732static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004733processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004734
4735 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4736 int newVoiceRadioTech;
4737 int newCdmaSubscriptionSource;
4738 int newSimStatus;
4739
4740 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4741 from Radio State and send change notifications if there has been a change */
4742 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4743 if(newVoiceRadioTech != voiceRadioTech) {
4744 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004745 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4746 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004747 }
4748 if(is3gpp2(newVoiceRadioTech)) {
4749 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4750 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4751 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004752 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4753 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004754 }
4755 }
4756 newSimStatus = decodeSimStatus(newRadioState);
4757 if(newSimStatus != simRuimStatus) {
4758 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004759 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004760 }
4761
4762 /* Send RADIO_ON to telephony */
4763 newRadioState = RADIO_STATE_ON;
4764 }
4765
4766 return newRadioState;
4767}
4768
Etan Cohend3652192014-06-20 08:28:44 -07004769
4770#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004771extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004772void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Etan Cohend3652192014-06-20 08:28:44 -07004773 size_t datalen, RIL_SOCKET_ID socket_id)
4774#else
4775extern "C"
Bernhard Rosenkränzerd613b962014-11-17 20:52:09 +01004776void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004777 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004778#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004779{
4780 int unsolResponseIndex;
4781 int ret;
4782 int64_t timeReceived = 0;
4783 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004784 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004785 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4786
4787#if defined(ANDROID_MULTI_SIM)
4788 soc_id = socket_id;
4789#endif
4790
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004791
4792 if (s_registerCalled == 0) {
4793 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004794 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004795 return;
4796 }
Wink Saville7f856802009-06-09 10:23:37 -07004797
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004798 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4799
4800 if ((unsolResponseIndex < 0)
4801 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004802 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004803 return;
4804 }
4805
4806 // Grab a wake lock if needed for this reponse,
4807 // as we exit we'll either release it immediately
4808 // or set a timer to release it later.
4809 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4810 case WAKE_PARTIAL:
4811 grabPartialWakeLock();
4812 shouldScheduleTimeout = true;
4813 break;
4814
4815 case DONT_WAKE:
4816 default:
4817 // No wake lock is grabed so don't set timeout
4818 shouldScheduleTimeout = false;
4819 break;
4820 }
4821
4822 // Mark the time this was received, doing this
4823 // after grabing the wakelock incase getting
4824 // the elapsedRealTime might cause us to goto
4825 // sleep.
4826 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4827 timeReceived = elapsedRealtime();
4828 }
4829
4830 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4831
4832 Parcel p;
4833
4834 p.writeInt32 (RESPONSE_UNSOLICITED);
4835 p.writeInt32 (unsolResponse);
4836
4837 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004838 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004839 if (ret != 0) {
4840 // Problem with the response. Don't continue;
4841 goto error_exit;
4842 }
4843
4844 // some things get more payload
4845 switch(unsolResponse) {
4846 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004847 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004848 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004849 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004850 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004851 break;
4852
4853
4854 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4855 // Store the time that this was received so the
4856 // handler of this message can account for
4857 // the time it takes to arrive and process. In
4858 // particular the system has been known to sleep
4859 // before this message can be processed.
4860 p.writeInt64(timeReceived);
4861 break;
4862 }
4863
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004864#if VDBG
Etan Cohend3652192014-06-20 08:28:44 -07004865 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwalt191e4dc2015-04-29 16:57:39 -07004866#endif
Etan Cohend3652192014-06-20 08:28:44 -07004867 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004868 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4869
4870 // Unfortunately, NITZ time is not poll/update like everything
4871 // else in the system. So, if the upstream client isn't connected,
4872 // keep a copy of the last NITZ response (with receive time noted
4873 // above) around so we can deliver it when it is connected
4874
4875 if (s_lastNITZTimeData != NULL) {
4876 free (s_lastNITZTimeData);
4877 s_lastNITZTimeData = NULL;
4878 }
4879
4880 s_lastNITZTimeData = malloc(p.dataSize());
4881 s_lastNITZTimeDataSize = p.dataSize();
4882 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4883 }
4884
4885 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4886 // FIXME The java code should handshake here to release wake lock
4887
4888 if (shouldScheduleTimeout) {
4889 // Cancel the previous request
4890 if (s_last_wake_timeout_info != NULL) {
4891 s_last_wake_timeout_info->userParam = (void *)1;
4892 }
4893
4894 s_last_wake_timeout_info
4895 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4896 &TIMEVAL_WAKE_TIMEOUT);
4897 }
4898
4899 // Normal exit
4900 return;
4901
4902error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004903 if (shouldScheduleTimeout) {
4904 releaseWakeLock();
4905 }
4906}
4907
Wink Saville7f856802009-06-09 10:23:37 -07004908/** FIXME generalize this if you track UserCAllbackInfo, clear it
4909 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004910*/
4911static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004912internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004913 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004914{
4915 struct timeval myRelativeTime;
4916 UserCallbackInfo *p_info;
4917
4918 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4919
Wink Saville7f856802009-06-09 10:23:37 -07004920 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004921 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004922
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004923 if (relativeTime == NULL) {
4924 /* treat null parameter as a 0 relative time */
4925 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4926 } else {
4927 /* FIXME I think event_add's tv param is really const anyway */
4928 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4929 }
4930
4931 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4932
4933 ril_timer_add(&(p_info->event), &myRelativeTime);
4934
4935 triggerEvLoop();
4936 return p_info;
4937}
4938
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004939
4940extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004941RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4942 const struct timeval *relativeTime) {
4943 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004944}
4945
4946const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004947failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004948 switch(e) {
4949 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004950 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004951 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4952 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4953 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4954 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4955 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4956 case RIL_E_CANCELLED: return "E_CANCELLED";
4957 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4958 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4959 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004960 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004961 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004962#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004963 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4964 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4965#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004966 default: return "<unknown error>";
4967 }
4968}
4969
4970const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004971radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004972 switch(s) {
4973 case RADIO_STATE_OFF: return "RADIO_OFF";
4974 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4975 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4976 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4977 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004978 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4979 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4980 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4981 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4982 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004983 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004984 default: return "<unknown state>";
4985 }
4986}
4987
4988const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004989callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004990 switch(s) {
4991 case RIL_CALL_ACTIVE : return "ACTIVE";
4992 case RIL_CALL_HOLDING: return "HOLDING";
4993 case RIL_CALL_DIALING: return "DIALING";
4994 case RIL_CALL_ALERTING: return "ALERTING";
4995 case RIL_CALL_INCOMING: return "INCOMING";
4996 case RIL_CALL_WAITING: return "WAITING";
4997 default: return "<unknown state>";
4998 }
4999}
5000
5001const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07005002requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005003/*
5004 cat libs/telephony/ril_commands.h \
5005 | egrep "^ *{RIL_" \
5006 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5007
5008
5009 cat libs/telephony/ril_unsol_commands.h \
5010 | egrep "^ *{RIL_" \
5011 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5012
5013*/
5014 switch(request) {
5015 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5016 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5017 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5018 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5019 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5020 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5021 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5022 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5023 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5024 case RIL_REQUEST_DIAL: return "DIAL";
5025 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5026 case RIL_REQUEST_HANGUP: return "HANGUP";
5027 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5028 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5029 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5030 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5031 case RIL_REQUEST_UDUB: return "UDUB";
5032 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5033 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08005034 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5035 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005036 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5037 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5038 case RIL_REQUEST_DTMF: return "DTMF";
5039 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5040 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005041 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005042 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5043 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5044 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5045 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5046 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5047 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5048 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5049 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5050 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5051 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5052 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5053 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5054 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07005055 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005056 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5057 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5058 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5059 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5060 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5061 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5062 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5063 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5064 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5065 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5066 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5067 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5068 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5069 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5070 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5071 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5072 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07005073 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5074 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005075 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5076 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5077 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07005078 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5079 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005080 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5081 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5082 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5083 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5084 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5085 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5086 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5087 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08005088 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07005089 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5090 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5091 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5092 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5093 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5094 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5095 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5096 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5097 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5098 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07005099 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5100 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5101 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5102 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5103 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07005104 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07005105 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5106 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5107 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5108 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07005109 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5110 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5111 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07005112 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07005113 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08005114 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07005115 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07005116 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5117 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005118 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Naveen Kalla99f88fe2011-11-15 11:19:30 -08005119 case RIL_REQUEST_WRITE_SMS_TO_SIM: return "WRITE_SMS_TO_SIM";
Wink Saville8a9e0212013-04-09 12:11:38 -07005120 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5121 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07005122 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005123 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5124 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08005125 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5126 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5127 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5128 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005129 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5130 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Preeti Ahujadbff97e2014-08-21 16:26:24 -07005131 case RIL_REQUEST_SIM_GET_ATR: return "SIM_GET_ATR";
Etan Cohend3652192014-06-20 08:28:44 -07005132 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5133 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
Amit Mahajan2b772032014-06-26 14:20:11 -07005134 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5135 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
Wink Savillec29360a2014-07-13 05:17:28 -07005136 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5137 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
Amit Mahajanc796e222014-08-13 16:54:01 +00005138 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005139 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5140 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005141 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 -08005142 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5143 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5144 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5145 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5146 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5147 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5148 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Naveen Kalla99f88fe2011-11-15 11:19:30 -08005149 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005150 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5151 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5152 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5153 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5154 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5155 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07005156 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005157 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07005158 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5159 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5160 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5161 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07005162 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5163 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5164 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5165 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5166 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07005167 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07005168 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08005169 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07005170 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08005171 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5172 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07005173 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08005174 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07005175 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07005176 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07005177 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5178 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5179 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
Wink Savillec29360a2014-07-13 05:17:28 -07005180 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Naveen Kallaa65a16a2014-07-31 16:48:31 -07005181 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Wink Saville8b4e4f72014-10-17 15:01:45 -07005182 case RIL_UNSOL_RADIO_CAPABILITY: return "RIL_UNSOL_RADIO_CAPABILITY";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005183 default: return "<unknown request>";
5184 }
5185}
5186
Etan Cohend3652192014-06-20 08:28:44 -07005187const char *
5188rilSocketIdToString(RIL_SOCKET_ID socket_id)
5189{
5190 switch(socket_id) {
5191 case RIL_SOCKET_1:
5192 return "RIL_SOCKET_1";
5193#if (SIM_COUNT >= 2)
5194 case RIL_SOCKET_2:
5195 return "RIL_SOCKET_2";
5196#endif
5197#if (SIM_COUNT >= 3)
5198 case RIL_SOCKET_3:
5199 return "RIL_SOCKET_3";
5200#endif
5201#if (SIM_COUNT >= 4)
5202 case RIL_SOCKET_4:
5203 return "RIL_SOCKET_4";
5204#endif
5205 default:
5206 return "not a valid RIL";
5207 }
5208}
5209
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08005210} /* namespace android */
Dheeraj Shetty27976c42014-07-02 21:27:57 +02005211
5212void rilEventAddWakeup_helper(struct ril_event *ev) {
5213 android::rilEventAddWakeup(ev);
5214}
5215
5216void listenCallback_helper(int fd, short flags, void *param) {
5217 android::listenCallback(fd, flags, param);
5218}
5219
5220int blockingWrite_helper(int fd, void *buffer, size_t len) {
5221 return android::blockingWrite(fd, buffer, len);
5222}