blob: ef93e5b8c069e22937e7f3f514fa687a99fd61c3 [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
22#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070023#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080024#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070026#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070030#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <cutils/jstring.h>
32
33#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070034#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
68
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Constants for response types */
84#define RESPONSE_SOLICITED 0
85#define RESPONSE_UNSOLICITED 1
86
87/* Negative values for private RIL errno's */
88#define RIL_ERRNO_INVALID_RESPONSE -1
89
90// request, response, and unsolicited msg print macro
91#define PRINTBUF_SIZE 8096
92
93// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
108 #define appendPrintBuf(x...) sprintf(printBuf, x)
109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700136 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700141 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142} RequestInfo;
143
Wink Saville3d54e742009-05-18 18:00:44 -0700144typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Etan Cohend3652192014-06-20 08:28:44 -0700151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
185static struct ril_event s_commands_event;
186static struct ril_event s_wakeupfd_event;
187static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700188static SocketListenParam s_ril_param_socket;
189
190static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests = NULL;
193
194#if (SIM_COUNT >= 2)
195static struct ril_event s_commands_event_socket2;
196static struct ril_event s_listen_event_socket2;
197static SocketListenParam s_ril_param_socket2;
198
199static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
200static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
201static RequestInfo *s_pendingRequests_socket2 = NULL;
202#endif
203
204#if (SIM_COUNT >= 3)
205static struct ril_event s_commands_event_socket3;
206static struct ril_event s_listen_event_socket3;
207static SocketListenParam s_ril_param_socket3;
208
209static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
210static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
211static RequestInfo *s_pendingRequests_socket3 = NULL;
212#endif
213
214#if (SIM_COUNT >= 4)
215static struct ril_event s_commands_event_socket4;
216static struct ril_event s_listen_event_socket4;
217static SocketListenParam s_ril_param_socket4;
218
219static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
220static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
221static RequestInfo *s_pendingRequests_socket4 = NULL;
222#endif
223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static struct ril_event s_wake_timeout_event;
225static struct ril_event s_debug_event;
226
227
228static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
229
Etan Cohend3652192014-06-20 08:28:44 -0700230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233
234static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
236
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800237static RequestInfo *s_toDispatchHead = NULL;
238static RequestInfo *s_toDispatchTail = NULL;
239
240static UserCallbackInfo *s_last_wake_timeout_info = NULL;
241
242static void *s_lastNITZTimeData = NULL;
243static size_t s_lastNITZTimeDataSize;
244
245#if RILC_LOG
246 static char printBuf[PRINTBUF_SIZE];
247#endif
248
249/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700250static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800251
252static void dispatchVoid (Parcel& p, RequestInfo *pRI);
253static void dispatchString (Parcel& p, RequestInfo *pRI);
254static void dispatchStrings (Parcel& p, RequestInfo *pRI);
255static void dispatchInts (Parcel& p, RequestInfo *pRI);
256static void dispatchDial (Parcel& p, RequestInfo *pRI);
257static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800258static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
260static void dispatchRaw(Parcel& p, RequestInfo *pRI);
261static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700262static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800263static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700264static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800265static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800266
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700268static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
269static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
270static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700272static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700273static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
274static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800275static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
276static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700277static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700278static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000279static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700280static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800281static int responseInts(Parcel &p, void *response, size_t responselen);
282static int responseStrings(Parcel &p, void *response, size_t responselen);
283static int responseString(Parcel &p, void *response, size_t responselen);
284static int responseVoid(Parcel &p, void *response, size_t responselen);
285static int responseCallList(Parcel &p, void *response, size_t responselen);
286static int responseSMS(Parcel &p, void *response, size_t responselen);
287static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
288static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700289static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800290static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800291static int responseRaw(Parcel &p, void *response, size_t responselen);
292static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700294static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
295static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700296static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800297static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700298static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
299static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
300static int responseCallRing(Parcel &p, void *response, size_t responselen);
301static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
302static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800303static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700304static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700305static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700306static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700307static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Amit Mahajan54563d32014-11-22 00:54:49 +0000308static int responseSSData(Parcel &p, void *response, size_t responselen);
309
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800310static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
311static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
312static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
313
Amit Mahajan54563d32014-11-22 00:54:49 +0000314static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
315
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800316#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700317#if defined(ANDROID_MULTI_SIM)
318extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
319 size_t datalen, RIL_SOCKET_ID socket_id);
320#else
Wink Saville7f856802009-06-09 10:23:37 -0700321extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800322 size_t datalen);
323#endif
Etan Cohend3652192014-06-20 08:28:44 -0700324#endif
325
326#if defined(ANDROID_MULTI_SIM)
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
330#else
331#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
332#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
333#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
334#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
Wink Saville7f856802009-06-09 10:23:37 -0700336static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700337 (RIL_TimedCallback callback, void *param,
338 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800339
340/** Index == requestNumber */
341static CommandInfo s_commands[] = {
342#include "ril_commands.h"
343};
344
345static UnsolResponseInfo s_unsolResponses[] = {
346#include "ril_unsol_commands.h"
347};
348
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800349/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
350 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
351 radio state message and store it. Every time there is a change in Radio State
352 check to see if voice radio tech changes and notify telephony
353 */
354int voiceRadioTech = -1;
355
356/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
357 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
358 source from radio state and store it. Every time there is a change in Radio State
359 check to see if subscription source changed and notify telephony
360 */
361int cdmaSubscriptionSource = -1;
362
363/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
364 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
365 check to see if SIM/RUIM status changed and notify telephony
366 */
367int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800368
Etan Cohend3652192014-06-20 08:28:44 -0700369static char * RIL_getRilSocketName() {
370 return rild;
371}
372
373extern "C"
374void RIL_setRilSocketName(char * s) {
375 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
376}
377
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800378static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700379strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800380 size_t stringlen;
381 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700382
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800383 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700384
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800385 return strndup16to8(s16, stringlen);
386}
387
Wink Saville8b4e4f72014-10-17 15:01:45 -0700388static status_t
389readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
390 size_t s16Len;
391 const char16_t *s16;
392
393 s16 = p.readString16Inplace(&s16Len);
394 if (s16 == NULL) {
395 return NO_MEMORY;
396 }
397 size_t strLen = strnlen16to8(s16, s16Len);
398 if ((strLen + 1) > maxLen) {
399 return NO_MEMORY;
400 }
401 if (strncpy16to8(str, s16, strLen) == NULL) {
402 return NO_MEMORY;
403 } else {
404 return NO_ERROR;
405 }
406}
407
Wink Savillef4c4d362009-04-02 01:37:03 -0700408static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 char16_t *s16;
410 size_t s16_len;
411 s16 = strdup8to16(s, &s16_len);
412 p.writeString16(s16, s16_len);
413 free(s16);
414}
415
416
417static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700418memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800419 if (s != NULL) {
420 memset (s, 0, strlen(s));
421 }
422}
423
424void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
425 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700426 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 // do nothing -- the data reference lives longer than the Parcel object
428}
429
Wink Saville7f856802009-06-09 10:23:37 -0700430/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800431 * To be called from dispatch thread
432 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700433 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800434 */
435static void
Etan Cohend3652192014-06-20 08:28:44 -0700436issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800437 RequestInfo *pRI;
438 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700439 /* Hook for current context */
440 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
441 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
442 /* pendingRequestsHook refer to &s_pendingRequests */
443 RequestInfo** pendingRequestsHook = &s_pendingRequests;
444
445#if (SIM_COUNT == 2)
446 if (socket_id == RIL_SOCKET_2) {
447 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
448 pendingRequestsHook = &s_pendingRequests_socket2;
449 }
450#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800451
452 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
453
454 pRI->local = 1;
455 pRI->token = 0xffffffff; // token is not used in this context
456 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700457 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800458
Etan Cohend3652192014-06-20 08:28:44 -0700459 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460 assert (ret == 0);
461
Etan Cohend3652192014-06-20 08:28:44 -0700462 pRI->p_next = *pendingRequestsHook;
463 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800464
Etan Cohend3652192014-06-20 08:28:44 -0700465 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800466 assert (ret == 0);
467
Wink Saville8eb2a122012-11-19 16:05:13 -0800468 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800469
Etan Cohend3652192014-06-20 08:28:44 -0700470 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800471}
472
473
474
475static int
Etan Cohend3652192014-06-20 08:28:44 -0700476processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800477 Parcel p;
478 status_t status;
479 int32_t request;
480 int32_t token;
481 RequestInfo *pRI;
482 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700483 /* Hook for current context */
484 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
485 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
486 /* pendingRequestsHook refer to &s_pendingRequests */
487 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800488
489 p.setData((uint8_t *) buffer, buflen);
490
491 // status checked at end
492 status = p.readInt32(&request);
493 status = p.readInt32 (&token);
494
Etan Cohend3652192014-06-20 08:28:44 -0700495 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
496
497#if (SIM_COUNT >= 2)
498 if (socket_id == RIL_SOCKET_2) {
499 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
500 pendingRequestsHook = &s_pendingRequests_socket2;
501 }
502#if (SIM_COUNT >= 3)
503 else if (socket_id == RIL_SOCKET_3) {
504 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
505 pendingRequestsHook = &s_pendingRequests_socket3;
506 }
507#endif
508#if (SIM_COUNT >= 4)
509 else if (socket_id == RIL_SOCKET_4) {
510 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
511 pendingRequestsHook = &s_pendingRequests_socket4;
512 }
513#endif
514#endif
515
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800516 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800517 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800518 return 0;
519 }
520
521 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700522 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800523 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800524 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700525 pErr.writeInt32 (RESPONSE_SOLICITED);
526 pErr.writeInt32 (token);
527 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
528
529 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800530 return 0;
531 }
532
533
534 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
535
536 pRI->token = token;
537 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700538 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539
Etan Cohend3652192014-06-20 08:28:44 -0700540 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541 assert (ret == 0);
542
Etan Cohend3652192014-06-20 08:28:44 -0700543 pRI->p_next = *pendingRequestsHook;
544 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545
Etan Cohend3652192014-06-20 08:28:44 -0700546 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800547 assert (ret == 0);
548
549/* sLastDispatchedToken = token; */
550
Wink Saville7f856802009-06-09 10:23:37 -0700551 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800552
553 return 0;
554}
555
556static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700557invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800558 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559 pRI->token, requestToString(pRI->pCI->requestNumber));
560}
561
562/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700563static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700564dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800565 clearPrintBuf;
566 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700567 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800568}
569
570/** Callee expects const char * */
571static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700572dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800573 status_t status;
574 size_t datalen;
575 size_t stringlen;
576 char *string8 = NULL;
577
578 string8 = strdupReadString(p);
579
580 startRequest;
581 appendPrintBuf("%s%s", printBuf, string8);
582 closeRequest;
583 printRequest(pRI->token, pRI->pCI->requestNumber);
584
Etan Cohend3652192014-06-20 08:28:44 -0700585 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
586 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800587
588#ifdef MEMSET_FREED
589 memsetString(string8);
590#endif
591
592 free(string8);
593 return;
594invalid:
595 invalidCommandBlock(pRI);
596 return;
597}
598
599/** Callee expects const char ** */
600static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700601dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800602 int32_t countStrings;
603 status_t status;
604 size_t datalen;
605 char **pStrings;
606
607 status = p.readInt32 (&countStrings);
608
609 if (status != NO_ERROR) {
610 goto invalid;
611 }
612
613 startRequest;
614 if (countStrings == 0) {
615 // just some non-null pointer
616 pStrings = (char **)alloca(sizeof(char *));
617 datalen = 0;
618 } else if (((int)countStrings) == -1) {
619 pStrings = NULL;
620 datalen = 0;
621 } else {
622 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700623
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800624 pStrings = (char **)alloca(datalen);
625
626 for (int i = 0 ; i < countStrings ; i++) {
627 pStrings[i] = strdupReadString(p);
628 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
629 }
630 }
631 removeLastChar;
632 closeRequest;
633 printRequest(pRI->token, pRI->pCI->requestNumber);
634
Etan Cohend3652192014-06-20 08:28:44 -0700635 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800636
637 if (pStrings != NULL) {
638 for (int i = 0 ; i < countStrings ; i++) {
639#ifdef MEMSET_FREED
640 memsetString (pStrings[i]);
641#endif
642 free(pStrings[i]);
643 }
644
645#ifdef MEMSET_FREED
646 memset(pStrings, 0, datalen);
647#endif
648 }
Wink Saville7f856802009-06-09 10:23:37 -0700649
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800650 return;
651invalid:
652 invalidCommandBlock(pRI);
653 return;
654}
655
656/** Callee expects const int * */
657static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700658dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800659 int32_t count;
660 status_t status;
661 size_t datalen;
662 int *pInts;
663
664 status = p.readInt32 (&count);
665
666 if (status != NO_ERROR || count == 0) {
667 goto invalid;
668 }
669
670 datalen = sizeof(int) * count;
671 pInts = (int *)alloca(datalen);
672
673 startRequest;
674 for (int i = 0 ; i < count ; i++) {
675 int32_t t;
676
677 status = p.readInt32(&t);
678 pInts[i] = (int)t;
679 appendPrintBuf("%s%d,", printBuf, t);
680
681 if (status != NO_ERROR) {
682 goto invalid;
683 }
684 }
685 removeLastChar;
686 closeRequest;
687 printRequest(pRI->token, pRI->pCI->requestNumber);
688
Etan Cohend3652192014-06-20 08:28:44 -0700689 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
690 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800691
692#ifdef MEMSET_FREED
693 memset(pInts, 0, datalen);
694#endif
695
696 return;
697invalid:
698 invalidCommandBlock(pRI);
699 return;
700}
701
702
Wink Saville7f856802009-06-09 10:23:37 -0700703/**
704 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800705 * Payload is:
706 * int32_t status
707 * String pdu
708 */
709static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700710dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800711 RIL_SMS_WriteArgs args;
712 int32_t t;
713 status_t status;
714
715 memset (&args, 0, sizeof(args));
716
717 status = p.readInt32(&t);
718 args.status = (int)t;
719
720 args.pdu = strdupReadString(p);
721
722 if (status != NO_ERROR || args.pdu == NULL) {
723 goto invalid;
724 }
725
726 args.smsc = strdupReadString(p);
727
728 startRequest;
729 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
730 (char*)args.pdu, (char*)args.smsc);
731 closeRequest;
732 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700733
Etan Cohend3652192014-06-20 08:28:44 -0700734 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800735
736#ifdef MEMSET_FREED
737 memsetString (args.pdu);
738#endif
739
740 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700741
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800742#ifdef MEMSET_FREED
743 memset(&args, 0, sizeof(args));
744#endif
745
746 return;
747invalid:
748 invalidCommandBlock(pRI);
749 return;
750}
751
Wink Saville7f856802009-06-09 10:23:37 -0700752/**
753 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754 * Payload is:
755 * String address
756 * int32_t clir
757 */
758static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700759dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800760 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800761 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800762 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800763 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800764 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800765 status_t status;
766
767 memset (&dial, 0, sizeof(dial));
768
769 dial.address = strdupReadString(p);
770
771 status = p.readInt32(&t);
772 dial.clir = (int)t;
773
774 if (status != NO_ERROR || dial.address == NULL) {
775 goto invalid;
776 }
777
Wink Saville3a4840b2010-04-07 13:29:58 -0700778 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800779 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800780 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800781 } else {
782 status = p.readInt32(&uusPresent);
783
784 if (status != NO_ERROR) {
785 goto invalid;
786 }
787
788 if (uusPresent == 0) {
789 dial.uusInfo = NULL;
790 } else {
791 int32_t len;
792
793 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
794
795 status = p.readInt32(&t);
796 uusInfo.uusType = (RIL_UUS_Type) t;
797
798 status = p.readInt32(&t);
799 uusInfo.uusDcs = (RIL_UUS_DCS) t;
800
801 status = p.readInt32(&len);
802 if (status != NO_ERROR) {
803 goto invalid;
804 }
805
806 // The java code writes -1 for null arrays
807 if (((int) len) == -1) {
808 uusInfo.uusData = NULL;
809 len = 0;
810 } else {
811 uusInfo.uusData = (char*) p.readInplace(len);
812 }
813
814 uusInfo.uusLength = len;
815 dial.uusInfo = &uusInfo;
816 }
Wink Saville7bce0822010-01-08 15:20:12 -0800817 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800818 }
819
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800820 startRequest;
821 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800822 if (uusPresent) {
823 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
824 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
825 dial.uusInfo->uusLength);
826 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800827 closeRequest;
828 printRequest(pRI->token, pRI->pCI->requestNumber);
829
Etan Cohend3652192014-06-20 08:28:44 -0700830 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800831
832#ifdef MEMSET_FREED
833 memsetString (dial.address);
834#endif
835
836 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700837
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800838#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800839 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800840 memset(&dial, 0, sizeof(dial));
841#endif
842
843 return;
844invalid:
845 invalidCommandBlock(pRI);
846 return;
847}
848
Wink Saville7f856802009-06-09 10:23:37 -0700849/**
850 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800851 * Payload is:
852 * int32_t command
853 * int32_t fileid
854 * String path
855 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700856 * String data
857 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800858 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800859 */
860static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700861dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800862 union RIL_SIM_IO {
863 RIL_SIM_IO_v6 v6;
864 RIL_SIM_IO_v5 v5;
865 } simIO;
866
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800868 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869 status_t status;
870
871 memset (&simIO, 0, sizeof(simIO));
872
Wink Saville7f856802009-06-09 10:23:37 -0700873 // note we only check status at the end
874
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800875 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800876 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800877
878 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800879 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800880
Wink Savillec0114b32011-02-18 10:14:07 -0800881 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800882
883 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800884 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885
886 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800887 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888
889 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800890 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800891
Wink Savillec0114b32011-02-18 10:14:07 -0800892 simIO.v6.data = strdupReadString(p);
893 simIO.v6.pin2 = strdupReadString(p);
894 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800895
896 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800897 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
898 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
899 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
900 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800901 closeRequest;
902 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700903
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800904 if (status != NO_ERROR) {
905 goto invalid;
906 }
907
Wink Savillec0114b32011-02-18 10:14:07 -0800908 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700909 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800910
911#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800912 memsetString (simIO.v6.path);
913 memsetString (simIO.v6.data);
914 memsetString (simIO.v6.pin2);
915 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800916#endif
917
Wink Savillec0114b32011-02-18 10:14:07 -0800918 free (simIO.v6.path);
919 free (simIO.v6.data);
920 free (simIO.v6.pin2);
921 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700922
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800923#ifdef MEMSET_FREED
924 memset(&simIO, 0, sizeof(simIO));
925#endif
926
927 return;
928invalid:
929 invalidCommandBlock(pRI);
930 return;
931}
932
933/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800934 * Callee expects const RIL_SIM_APDU *
935 * Payload is:
936 * int32_t sessionid
937 * int32_t cla
938 * int32_t instruction
939 * int32_t p1, p2, p3
940 * String data
941 */
942static void
943dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
944 int32_t t;
945 status_t status;
946 RIL_SIM_APDU apdu;
947
948 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
949
950 // Note we only check status at the end. Any single failure leads to
951 // subsequent reads filing.
952 status = p.readInt32(&t);
953 apdu.sessionid = (int)t;
954
955 status = p.readInt32(&t);
956 apdu.cla = (int)t;
957
958 status = p.readInt32(&t);
959 apdu.instruction = (int)t;
960
961 status = p.readInt32(&t);
962 apdu.p1 = (int)t;
963
964 status = p.readInt32(&t);
965 apdu.p2 = (int)t;
966
967 status = p.readInt32(&t);
968 apdu.p3 = (int)t;
969
970 apdu.data = strdupReadString(p);
971
972 startRequest;
973 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
974 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
975 apdu.p3, (char*)apdu.data);
976 closeRequest;
977 printRequest(pRI->token, pRI->pCI->requestNumber);
978
979 if (status != NO_ERROR) {
980 goto invalid;
981 }
982
Etan Cohend3652192014-06-20 08:28:44 -0700983 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800984
985#ifdef MEMSET_FREED
986 memsetString(apdu.data);
987#endif
988 free(apdu.data);
989
990#ifdef MEMSET_FREED
991 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
992#endif
993
994 return;
995invalid:
996 invalidCommandBlock(pRI);
997 return;
998}
999
1000
1001/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001002 * Callee expects const RIL_CallForwardInfo *
1003 * Payload is:
1004 * int32_t status/action
1005 * int32_t reason
1006 * int32_t serviceCode
1007 * int32_t toa
1008 * String number (0 length -> null)
1009 * int32_t timeSeconds
1010 */
Wink Saville7f856802009-06-09 10:23:37 -07001011static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001012dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001013 RIL_CallForwardInfo cff;
1014 int32_t t;
1015 status_t status;
1016
1017 memset (&cff, 0, sizeof(cff));
1018
Wink Saville7f856802009-06-09 10:23:37 -07001019 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001020
1021 status = p.readInt32(&t);
1022 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001023
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001024 status = p.readInt32(&t);
1025 cff.reason = (int)t;
1026
1027 status = p.readInt32(&t);
1028 cff.serviceClass = (int)t;
1029
1030 status = p.readInt32(&t);
1031 cff.toa = (int)t;
1032
1033 cff.number = strdupReadString(p);
1034
1035 status = p.readInt32(&t);
1036 cff.timeSeconds = (int)t;
1037
1038 if (status != NO_ERROR) {
1039 goto invalid;
1040 }
1041
1042 // special case: number 0-length fields is null
1043
1044 if (cff.number != NULL && strlen (cff.number) == 0) {
1045 cff.number = NULL;
1046 }
1047
1048 startRequest;
1049 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1050 cff.status, cff.reason, cff.serviceClass, cff.toa,
1051 (char*)cff.number, cff.timeSeconds);
1052 closeRequest;
1053 printRequest(pRI->token, pRI->pCI->requestNumber);
1054
Etan Cohend3652192014-06-20 08:28:44 -07001055 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001056
1057#ifdef MEMSET_FREED
1058 memsetString(cff.number);
1059#endif
1060
1061 free (cff.number);
1062
1063#ifdef MEMSET_FREED
1064 memset(&cff, 0, sizeof(cff));
1065#endif
1066
1067 return;
1068invalid:
1069 invalidCommandBlock(pRI);
1070 return;
1071}
1072
1073
Wink Saville7f856802009-06-09 10:23:37 -07001074static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001075dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001076 int32_t len;
1077 status_t status;
1078 const void *data;
1079
1080 status = p.readInt32(&len);
1081
1082 if (status != NO_ERROR) {
1083 goto invalid;
1084 }
1085
1086 // The java code writes -1 for null arrays
1087 if (((int)len) == -1) {
1088 data = NULL;
1089 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001090 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001091
1092 data = p.readInplace(len);
1093
1094 startRequest;
1095 appendPrintBuf("%sraw_size=%d", printBuf, len);
1096 closeRequest;
1097 printRequest(pRI->token, pRI->pCI->requestNumber);
1098
Etan Cohend3652192014-06-20 08:28:44 -07001099 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001100
1101 return;
1102invalid:
1103 invalidCommandBlock(pRI);
1104 return;
1105}
1106
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001107static status_t
1108constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001109 int32_t t;
1110 uint8_t ut;
1111 status_t status;
1112 int32_t digitCount;
1113 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001114
Wink Savillef4c4d362009-04-02 01:37:03 -07001115 memset(&rcsm, 0, sizeof(rcsm));
1116
1117 status = p.readInt32(&t);
1118 rcsm.uTeleserviceID = (int) t;
1119
1120 status = p.read(&ut,sizeof(ut));
1121 rcsm.bIsServicePresent = (uint8_t) ut;
1122
1123 status = p.readInt32(&t);
1124 rcsm.uServicecategory = (int) t;
1125
1126 status = p.readInt32(&t);
1127 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1128
1129 status = p.readInt32(&t);
1130 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1131
1132 status = p.readInt32(&t);
1133 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1134
1135 status = p.readInt32(&t);
1136 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1137
1138 status = p.read(&ut,sizeof(ut));
1139 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1140
1141 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1142 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1143 status = p.read(&ut,sizeof(ut));
1144 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1145 }
1146
Wink Saville7f856802009-06-09 10:23:37 -07001147 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001148 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1149
Wink Saville7f856802009-06-09 10:23:37 -07001150 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001151 rcsm.sSubAddress.odd = (uint8_t) ut;
1152
1153 status = p.read(&ut,sizeof(ut));
1154 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1155
1156 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001157 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1158 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001159 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1160 }
1161
Wink Saville7f856802009-06-09 10:23:37 -07001162 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001163 rcsm.uBearerDataLen = (int) t;
1164
1165 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001166 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1167 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001168 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1169 }
1170
1171 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001172 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001173 }
1174
1175 startRequest;
1176 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001177 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001178 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001179 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001180 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001181
Wink Savillef4c4d362009-04-02 01:37:03 -07001182 printRequest(pRI->token, pRI->pCI->requestNumber);
1183
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001184 return status;
1185}
1186
1187static void
1188dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1189 RIL_CDMA_SMS_Message rcsm;
1190
1191 ALOGD("dispatchCdmaSms");
1192 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1193 goto invalid;
1194 }
1195
Etan Cohend3652192014-06-20 08:28:44 -07001196 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001197
1198#ifdef MEMSET_FREED
1199 memset(&rcsm, 0, sizeof(rcsm));
1200#endif
1201
1202 return;
1203
1204invalid:
1205 invalidCommandBlock(pRI);
1206 return;
1207}
1208
Wink Saville7f856802009-06-09 10:23:37 -07001209static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001210dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1211 RIL_IMS_SMS_Message rism;
1212 RIL_CDMA_SMS_Message rcsm;
1213
1214 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1215
1216 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1217 goto invalid;
1218 }
1219 memset(&rism, 0, sizeof(rism));
1220 rism.tech = RADIO_TECH_3GPP2;
1221 rism.retry = retry;
1222 rism.messageRef = messageRef;
1223 rism.message.cdmaMessage = &rcsm;
1224
Etan Cohend3652192014-06-20 08:28:44 -07001225 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001226 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001227 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001228
1229#ifdef MEMSET_FREED
1230 memset(&rcsm, 0, sizeof(rcsm));
1231 memset(&rism, 0, sizeof(rism));
1232#endif
1233
1234 return;
1235
1236invalid:
1237 invalidCommandBlock(pRI);
1238 return;
1239}
1240
1241static void
1242dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1243 RIL_IMS_SMS_Message rism;
1244 int32_t countStrings;
1245 status_t status;
1246 size_t datalen;
1247 char **pStrings;
1248 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1249
1250 status = p.readInt32 (&countStrings);
1251
1252 if (status != NO_ERROR) {
1253 goto invalid;
1254 }
1255
1256 memset(&rism, 0, sizeof(rism));
1257 rism.tech = RADIO_TECH_3GPP;
1258 rism.retry = retry;
1259 rism.messageRef = messageRef;
1260
1261 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001262 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1263 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001264 if (countStrings == 0) {
1265 // just some non-null pointer
1266 pStrings = (char **)alloca(sizeof(char *));
1267 datalen = 0;
1268 } else if (((int)countStrings) == -1) {
1269 pStrings = NULL;
1270 datalen = 0;
1271 } else {
1272 datalen = sizeof(char *) * countStrings;
1273
1274 pStrings = (char **)alloca(datalen);
1275
1276 for (int i = 0 ; i < countStrings ; i++) {
1277 pStrings[i] = strdupReadString(p);
1278 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1279 }
1280 }
1281 removeLastChar;
1282 closeRequest;
1283 printRequest(pRI->token, pRI->pCI->requestNumber);
1284
1285 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001286 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001287 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001288 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001289
1290 if (pStrings != NULL) {
1291 for (int i = 0 ; i < countStrings ; i++) {
1292#ifdef MEMSET_FREED
1293 memsetString (pStrings[i]);
1294#endif
1295 free(pStrings[i]);
1296 }
1297
1298#ifdef MEMSET_FREED
1299 memset(pStrings, 0, datalen);
1300#endif
1301 }
1302
1303#ifdef MEMSET_FREED
1304 memset(&rism, 0, sizeof(rism));
1305#endif
1306 return;
1307invalid:
1308 ALOGE("dispatchImsGsmSms invalid block");
1309 invalidCommandBlock(pRI);
1310 return;
1311}
1312
1313static void
1314dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1315 int32_t t;
1316 status_t status = p.readInt32(&t);
1317 RIL_RadioTechnologyFamily format;
1318 uint8_t retry;
1319 int32_t messageRef;
1320
1321 ALOGD("dispatchImsSms");
1322 if (status != NO_ERROR) {
1323 goto invalid;
1324 }
1325 format = (RIL_RadioTechnologyFamily) t;
1326
1327 // read retry field
1328 status = p.read(&retry,sizeof(retry));
1329 if (status != NO_ERROR) {
1330 goto invalid;
1331 }
1332 // read messageRef field
1333 status = p.read(&messageRef,sizeof(messageRef));
1334 if (status != NO_ERROR) {
1335 goto invalid;
1336 }
1337
1338 if (RADIO_TECH_3GPP == format) {
1339 dispatchImsGsmSms(p, pRI, retry, messageRef);
1340 } else if (RADIO_TECH_3GPP2 == format) {
1341 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1342 } else {
1343 ALOGE("requestImsSendSMS invalid format value =%d", format);
1344 }
1345
1346 return;
1347
1348invalid:
1349 invalidCommandBlock(pRI);
1350 return;
1351}
1352
1353static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001354dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1355 RIL_CDMA_SMS_Ack rcsa;
1356 int32_t t;
1357 status_t status;
1358 int32_t digitCount;
1359
1360 memset(&rcsa, 0, sizeof(rcsa));
1361
1362 status = p.readInt32(&t);
1363 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1364
1365 status = p.readInt32(&t);
1366 rcsa.uSMSCauseCode = (int) t;
1367
1368 if (status != NO_ERROR) {
1369 goto invalid;
1370 }
1371
1372 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001373 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1374 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001375 closeRequest;
1376
1377 printRequest(pRI->token, pRI->pCI->requestNumber);
1378
Etan Cohend3652192014-06-20 08:28:44 -07001379 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001380
1381#ifdef MEMSET_FREED
1382 memset(&rcsa, 0, sizeof(rcsa));
1383#endif
1384
1385 return;
1386
1387invalid:
1388 invalidCommandBlock(pRI);
1389 return;
1390}
1391
Wink Savillea592eeb2009-05-22 13:26:36 -07001392static void
1393dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1394 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001395 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001396 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001397
Wink Savillea592eeb2009-05-22 13:26:36 -07001398 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001399 if (status != NO_ERROR) {
1400 goto invalid;
1401 }
1402
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001403 {
1404 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1405 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001406
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001407 startRequest;
1408 for (int i = 0 ; i < num ; i++ ) {
1409 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001410
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001411 status = p.readInt32(&t);
1412 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001413
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001414 status = p.readInt32(&t);
1415 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001416
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001417 status = p.readInt32(&t);
1418 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001419
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 status = p.readInt32(&t);
1421 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001422
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001423 status = p.readInt32(&t);
1424 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001425
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001426 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1427 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1428 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1429 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1430 gsmBci[i].selected);
1431 }
1432 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001433
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001434 if (status != NO_ERROR) {
1435 goto invalid;
1436 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001437
Etan Cohend3652192014-06-20 08:28:44 -07001438 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001439 gsmBciPtrs,
1440 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001441 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001442
1443#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001444 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1445 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001446#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001447 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001448
1449 return;
1450
1451invalid:
1452 invalidCommandBlock(pRI);
1453 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001454}
Wink Savillef4c4d362009-04-02 01:37:03 -07001455
Wink Savillea592eeb2009-05-22 13:26:36 -07001456static void
1457dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1458 int32_t t;
1459 status_t status;
1460 int32_t num;
1461
1462 status = p.readInt32(&num);
1463 if (status != NO_ERROR) {
1464 goto invalid;
1465 }
1466
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 {
1468 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1469 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001470
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001471 startRequest;
1472 for (int i = 0 ; i < num ; i++ ) {
1473 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001474
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 status = p.readInt32(&t);
1476 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 status = p.readInt32(&t);
1479 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001480
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001481 status = p.readInt32(&t);
1482 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001483
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1485 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1486 cdmaBci[i].language, cdmaBci[i].selected);
1487 }
1488 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001489
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001490 if (status != NO_ERROR) {
1491 goto invalid;
1492 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001493
Etan Cohend3652192014-06-20 08:28:44 -07001494 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001495 cdmaBciPtrs,
1496 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001497 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
1499#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001500 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1501 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001502#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001503 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001504
1505 return;
1506
1507invalid:
1508 invalidCommandBlock(pRI);
1509 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001510}
1511
1512static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1513 RIL_CDMA_SMS_WriteArgs rcsw;
1514 int32_t t;
1515 uint32_t ut;
1516 uint8_t uct;
1517 status_t status;
1518 int32_t digitCount;
1519
1520 memset(&rcsw, 0, sizeof(rcsw));
1521
1522 status = p.readInt32(&t);
1523 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001524
Wink Savillef4c4d362009-04-02 01:37:03 -07001525 status = p.readInt32(&t);
1526 rcsw.message.uTeleserviceID = (int) t;
1527
1528 status = p.read(&uct,sizeof(uct));
1529 rcsw.message.bIsServicePresent = (uint8_t) uct;
1530
1531 status = p.readInt32(&t);
1532 rcsw.message.uServicecategory = (int) t;
1533
1534 status = p.readInt32(&t);
1535 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1536
1537 status = p.readInt32(&t);
1538 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1539
1540 status = p.readInt32(&t);
1541 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1542
1543 status = p.readInt32(&t);
1544 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1545
1546 status = p.read(&uct,sizeof(uct));
1547 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1548
1549 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1550 status = p.read(&uct,sizeof(uct));
1551 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1552 }
1553
Wink Savillea592eeb2009-05-22 13:26:36 -07001554 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001555 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1556
Wink Savillea592eeb2009-05-22 13:26:36 -07001557 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001558 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1559
1560 status = p.read(&uct,sizeof(uct));
1561 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1562
1563 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001564 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001565 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1566 }
1567
Wink Savillea592eeb2009-05-22 13:26:36 -07001568 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001569 rcsw.message.uBearerDataLen = (int) t;
1570
1571 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001572 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001573 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1574 }
1575
1576 if (status != NO_ERROR) {
1577 goto invalid;
1578 }
1579
1580 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001581 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1582 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1583 message.sAddress.number_mode=%d, \
1584 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001585 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001586 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1587 rcsw.message.sAddress.number_mode,
1588 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001589 closeRequest;
1590
1591 printRequest(pRI->token, pRI->pCI->requestNumber);
1592
Etan Cohend3652192014-06-20 08:28:44 -07001593 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001594
1595#ifdef MEMSET_FREED
1596 memset(&rcsw, 0, sizeof(rcsw));
1597#endif
1598
1599 return;
1600
1601invalid:
1602 invalidCommandBlock(pRI);
1603 return;
1604
1605}
1606
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001607// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1608// Version 4 of the RIL interface adds a new PDP type parameter to support
1609// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1610// RIL, remove the parameter from the request.
1611static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1612 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1613 const int numParamsRilV3 = 6;
1614
1615 // The first bytes of the RIL parcel contain the request number and the
1616 // serial number - see processCommandBuffer(). Copy them over too.
1617 int pos = p.dataPosition();
1618
1619 int numParams = p.readInt32();
1620 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1621 Parcel p2;
1622 p2.appendFrom(&p, 0, pos);
1623 p2.writeInt32(numParamsRilV3);
1624 for(int i = 0; i < numParamsRilV3; i++) {
1625 p2.writeString16(p.readString16());
1626 }
1627 p2.setDataPosition(pos);
1628 dispatchStrings(p2, pRI);
1629 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001630 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001631 dispatchStrings(p, pRI);
1632 }
1633}
1634
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001635// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1636// When all RILs handle this request, this function can be removed and
1637// the request can be sent directly to the RIL using dispatchVoid.
1638static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001639 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001640
1641 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1642 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1643 }
1644
1645 // RILs that support RADIO_STATE_ON should support this request.
1646 if (RADIO_STATE_ON == state) {
1647 dispatchVoid(p, pRI);
1648 return;
1649 }
1650
1651 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1652 // will not support this new request either and decode Voice Radio Technology
1653 // from Radio State
1654 voiceRadioTech = decodeVoiceRadioTechnology(state);
1655
1656 if (voiceRadioTech < 0)
1657 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1658 else
1659 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1660}
1661
1662// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1663// When all RILs handle this request, this function can be removed and
1664// the request can be sent directly to the RIL using dispatchVoid.
1665static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001666 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001667
1668 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1669 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1670 }
1671
1672 // RILs that support RADIO_STATE_ON should support this request.
1673 if (RADIO_STATE_ON == state) {
1674 dispatchVoid(p, pRI);
1675 return;
1676 }
1677
1678 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1679 // will not support this new request either and decode CDMA Subscription Source
1680 // from Radio State
1681 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1682
1683 if (cdmaSubscriptionSource < 0)
1684 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1685 else
1686 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1687}
1688
Sungmin Choi75697532013-04-26 15:04:45 -07001689static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1690{
1691 RIL_InitialAttachApn pf;
1692 int32_t t;
1693 status_t status;
1694
1695 memset(&pf, 0, sizeof(pf));
1696
1697 pf.apn = strdupReadString(p);
1698 pf.protocol = strdupReadString(p);
1699
1700 status = p.readInt32(&t);
1701 pf.authtype = (int) t;
1702
1703 pf.username = strdupReadString(p);
1704 pf.password = strdupReadString(p);
1705
1706 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001707 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1708 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001709 closeRequest;
1710 printRequest(pRI->token, pRI->pCI->requestNumber);
1711
1712 if (status != NO_ERROR) {
1713 goto invalid;
1714 }
Etan Cohend3652192014-06-20 08:28:44 -07001715 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001716
1717#ifdef MEMSET_FREED
1718 memsetString(pf.apn);
1719 memsetString(pf.protocol);
1720 memsetString(pf.username);
1721 memsetString(pf.password);
1722#endif
1723
1724 free(pf.apn);
1725 free(pf.protocol);
1726 free(pf.username);
1727 free(pf.password);
1728
1729#ifdef MEMSET_FREED
1730 memset(&pf, 0, sizeof(pf));
1731#endif
1732
1733 return;
1734invalid:
1735 invalidCommandBlock(pRI);
1736 return;
1737}
1738
Jake Hamby8a4a2332014-01-15 13:12:05 -08001739static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1740 RIL_NV_ReadItem nvri;
1741 int32_t t;
1742 status_t status;
1743
1744 memset(&nvri, 0, sizeof(nvri));
1745
1746 status = p.readInt32(&t);
1747 nvri.itemID = (RIL_NV_Item) t;
1748
1749 if (status != NO_ERROR) {
1750 goto invalid;
1751 }
1752
1753 startRequest;
1754 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1755 closeRequest;
1756
1757 printRequest(pRI->token, pRI->pCI->requestNumber);
1758
Etan Cohend3652192014-06-20 08:28:44 -07001759 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001760
1761#ifdef MEMSET_FREED
1762 memset(&nvri, 0, sizeof(nvri));
1763#endif
1764
1765 return;
1766
1767invalid:
1768 invalidCommandBlock(pRI);
1769 return;
1770}
1771
1772static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1773 RIL_NV_WriteItem nvwi;
1774 int32_t t;
1775 status_t status;
1776
1777 memset(&nvwi, 0, sizeof(nvwi));
1778
1779 status = p.readInt32(&t);
1780 nvwi.itemID = (RIL_NV_Item) t;
1781
1782 nvwi.value = strdupReadString(p);
1783
1784 if (status != NO_ERROR || nvwi.value == NULL) {
1785 goto invalid;
1786 }
1787
1788 startRequest;
1789 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1790 nvwi.value);
1791 closeRequest;
1792
1793 printRequest(pRI->token, pRI->pCI->requestNumber);
1794
Etan Cohend3652192014-06-20 08:28:44 -07001795 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001796
1797#ifdef MEMSET_FREED
1798 memsetString(nvwi.value);
1799#endif
1800
1801 free(nvwi.value);
1802
1803#ifdef MEMSET_FREED
1804 memset(&nvwi, 0, sizeof(nvwi));
1805#endif
1806
1807 return;
1808
1809invalid:
1810 invalidCommandBlock(pRI);
1811 return;
1812}
1813
1814
Etan Cohend3652192014-06-20 08:28:44 -07001815static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1816 RIL_SelectUiccSub uicc_sub;
1817 status_t status;
1818 int32_t t;
1819 memset(&uicc_sub, 0, sizeof(uicc_sub));
1820
1821 status = p.readInt32(&t);
1822 if (status != NO_ERROR) {
1823 goto invalid;
1824 }
1825 uicc_sub.slot = (int) t;
1826
1827 status = p.readInt32(&t);
1828 if (status != NO_ERROR) {
1829 goto invalid;
1830 }
1831 uicc_sub.app_index = (int) t;
1832
1833 status = p.readInt32(&t);
1834 if (status != NO_ERROR) {
1835 goto invalid;
1836 }
1837 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1838
1839 status = p.readInt32(&t);
1840 if (status != NO_ERROR) {
1841 goto invalid;
1842 }
1843 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1844
1845 startRequest;
1846 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1847 uicc_sub.act_status);
1848 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1849 uicc_sub.app_index, uicc_sub.act_status);
1850 closeRequest;
1851 printRequest(pRI->token, pRI->pCI->requestNumber);
1852
1853 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1854
1855#ifdef MEMSET_FREED
1856 memset(&uicc_sub, 0, sizeof(uicc_sub));
1857#endif
1858 return;
1859
1860invalid:
1861 invalidCommandBlock(pRI);
1862 return;
1863}
1864
Amit Mahajan90530a62014-07-01 15:54:08 -07001865static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1866{
1867 RIL_SimAuthentication pf;
1868 int32_t t;
1869 status_t status;
1870
1871 memset(&pf, 0, sizeof(pf));
1872
1873 status = p.readInt32(&t);
1874 pf.authContext = (int) t;
1875 pf.authData = strdupReadString(p);
1876 pf.aid = strdupReadString(p);
1877
1878 startRequest;
1879 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1880 closeRequest;
1881 printRequest(pRI->token, pRI->pCI->requestNumber);
1882
1883 if (status != NO_ERROR) {
1884 goto invalid;
1885 }
1886 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1887
1888#ifdef MEMSET_FREED
1889 memsetString(pf.authData);
1890 memsetString(pf.aid);
1891#endif
1892
1893 free(pf.authData);
1894 free(pf.aid);
1895
1896#ifdef MEMSET_FREED
1897 memset(&pf, 0, sizeof(pf));
1898#endif
1899
1900 return;
1901invalid:
1902 invalidCommandBlock(pRI);
1903 return;
1904}
1905
Amit Mahajanc796e222014-08-13 16:54:01 +00001906static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1907 int32_t t;
1908 status_t status;
1909 int32_t num;
1910
1911 status = p.readInt32(&num);
1912 if (status != NO_ERROR) {
1913 goto invalid;
1914 }
1915
1916 {
1917 RIL_DataProfileInfo dataProfiles[num];
1918 RIL_DataProfileInfo *dataProfilePtrs[num];
1919
1920 startRequest;
1921 for (int i = 0 ; i < num ; i++ ) {
1922 dataProfilePtrs[i] = &dataProfiles[i];
1923
1924 status = p.readInt32(&t);
1925 dataProfiles[i].profileId = (int) t;
1926
1927 dataProfiles[i].apn = strdupReadString(p);
1928 dataProfiles[i].protocol = strdupReadString(p);
1929 status = p.readInt32(&t);
1930 dataProfiles[i].authType = (int) t;
1931
1932 dataProfiles[i].user = strdupReadString(p);
1933 dataProfiles[i].password = strdupReadString(p);
1934
1935 status = p.readInt32(&t);
1936 dataProfiles[i].type = (int) t;
1937
1938 status = p.readInt32(&t);
1939 dataProfiles[i].maxConnsTime = (int) t;
1940 status = p.readInt32(&t);
1941 dataProfiles[i].maxConns = (int) t;
1942 status = p.readInt32(&t);
1943 dataProfiles[i].waitTime = (int) t;
1944
1945 status = p.readInt32(&t);
1946 dataProfiles[i].enabled = (int) t;
1947
1948 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1949 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1950 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1951 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1952 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1953 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1954 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1955 }
1956 closeRequest;
1957 printRequest(pRI->token, pRI->pCI->requestNumber);
1958
1959 if (status != NO_ERROR) {
1960 goto invalid;
1961 }
1962 CALL_ONREQUEST(pRI->pCI->requestNumber,
1963 dataProfilePtrs,
1964 num * sizeof(RIL_DataProfileInfo *),
1965 pRI, pRI->socket_id);
1966
1967#ifdef MEMSET_FREED
1968 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1969 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1970#endif
1971 }
1972
1973 return;
1974
1975invalid:
1976 invalidCommandBlock(pRI);
1977 return;
1978}
1979
Wink Saville8b4e4f72014-10-17 15:01:45 -07001980static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1981 RIL_RadioCapability rc;
1982 int32_t t;
1983 status_t status;
1984
1985 memset (&rc, 0, sizeof(RIL_RadioCapability));
1986
1987 status = p.readInt32(&t);
1988 rc.version = (int)t;
1989 if (status != NO_ERROR) {
1990 goto invalid;
1991 }
1992
1993 status = p.readInt32(&t);
1994 rc.session= (int)t;
1995 if (status != NO_ERROR) {
1996 goto invalid;
1997 }
1998
1999 status = p.readInt32(&t);
2000 rc.phase= (int)t;
2001 if (status != NO_ERROR) {
2002 goto invalid;
2003 }
2004
2005 status = p.readInt32(&t);
2006 rc.rat = (int)t;
2007 if (status != NO_ERROR) {
2008 goto invalid;
2009 }
2010
2011 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2012 if (status != NO_ERROR) {
2013 goto invalid;
2014 }
2015
2016 status = p.readInt32(&t);
2017 rc.status = (int)t;
2018
2019 if (status != NO_ERROR) {
2020 goto invalid;
2021 }
2022
2023 startRequest;
2024 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002025 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2026 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002027
2028 closeRequest;
2029 printRequest(pRI->token, pRI->pCI->requestNumber);
2030
2031 CALL_ONREQUEST(pRI->pCI->requestNumber,
2032 &rc,
2033 sizeof(RIL_RadioCapability),
2034 pRI, pRI->socket_id);
2035 return;
2036invalid:
2037 invalidCommandBlock(pRI);
2038 return;
2039}
2040
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002041static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002042blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002043 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002044 const uint8_t *toWrite;
2045
2046 toWrite = (const uint8_t *)buffer;
2047
2048 while (writeOffset < len) {
2049 ssize_t written;
2050 do {
2051 written = write (fd, toWrite + writeOffset,
2052 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302053 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002054
2055 if (written >= 0) {
2056 writeOffset += written;
2057 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002058 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002059 close(fd);
2060 return -1;
2061 }
2062 }
2063
2064 return 0;
2065}
2066
2067static int
Etan Cohend3652192014-06-20 08:28:44 -07002068sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2069 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002070 int ret;
2071 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002072 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002073
Etan Cohend3652192014-06-20 08:28:44 -07002074 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2075
2076#if (SIM_COUNT >= 2)
2077 if (socket_id == RIL_SOCKET_2) {
2078 fd = s_ril_param_socket2.fdCommand;
2079 writeMutexHook = &s_writeMutex_socket2;
2080 }
2081#if (SIM_COUNT >= 3)
2082 else if (socket_id == RIL_SOCKET_3) {
2083 fd = s_ril_param_socket3.fdCommand;
2084 writeMutexHook = &s_writeMutex_socket3;
2085 }
2086#endif
2087#if (SIM_COUNT >= 4)
2088 else if (socket_id == RIL_SOCKET_4) {
2089 fd = s_ril_param_socket4.fdCommand;
2090 writeMutexHook = &s_writeMutex_socket4;
2091 }
2092#endif
2093#endif
2094 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002095 return -1;
2096 }
2097
2098 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002099 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2101
2102 return -1;
2103 }
Wink Saville7f856802009-06-09 10:23:37 -07002104
Etan Cohend3652192014-06-20 08:28:44 -07002105 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002106
2107 header = htonl(dataSize);
2108
2109 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2110
2111 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002112 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002113 return ret;
2114 }
2115
Kennyee1fadc2009-08-13 00:45:53 +08002116 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002117
2118 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002119 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002120 return ret;
2121 }
2122
Etan Cohend3652192014-06-20 08:28:44 -07002123 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124
2125 return 0;
2126}
2127
2128static int
Etan Cohend3652192014-06-20 08:28:44 -07002129sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002130 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002131 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132}
2133
Mohamad Ayyash74f7e662014-04-18 11:43:28 -0700