blob: 41d11a8694f96e1484e8ea7280f1c28c5e5b146b [file] [log] [blame]
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Wink Saville7f856802009-06-09 10:23:37 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08008**
Wink Saville7f856802009-06-09 10:23:37 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080010**
Wink Saville7f856802009-06-09 10:23:37 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
21
22#include <telephony/ril.h>
Wink Savillef4c4d362009-04-02 01:37:03 -070023#include <telephony/ril_cdma_sms.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080024#include <cutils/sockets.h>
25#include <cutils/jstring.h>
Dima Zavin622bf2b2013-05-22 11:29:34 -070026#include <telephony/record_stream.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080027#include <utils/Log.h>
28#include <utils/SystemClock.h>
29#include <pthread.h>
Mathias Agopian8a3c48c2009-05-19 19:11:50 -070030#include <binder/Parcel.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080031#include <cutils/jstring.h>
32
33#include <sys/types.h>
Wink Saville18e4ab12013-04-07 17:31:04 -070034#include <sys/limits.h>
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080035#include <pwd.h>
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <stdarg.h>
40#include <string.h>
41#include <unistd.h>
42#include <fcntl.h>
43#include <time.h>
44#include <errno.h>
45#include <assert.h>
46#include <ctype.h>
47#include <alloca.h>
48#include <sys/un.h>
49#include <assert.h>
50#include <netinet/in.h>
51#include <cutils/properties.h>
52
53#include <ril_event.h>
54
55namespace android {
56
57#define PHONE_PROCESS "radio"
58
59#define SOCKET_NAME_RIL "rild"
Etan Cohend3652192014-06-20 08:28:44 -070060#define SOCKET2_NAME_RIL "rild2"
61#define SOCKET3_NAME_RIL "rild3"
62#define SOCKET4_NAME_RIL "rild4"
63
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080064#define SOCKET_NAME_RIL_DEBUG "rild-debug"
65
66#define ANDROID_WAKE_LOCK_NAME "radio-interface"
67
68
69#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
70
71// match with constant in RIL.java
72#define MAX_COMMAND_BYTES (8 * 1024)
73
74// Basically: memset buffers that the client library
75// shouldn't be using anymore in an attempt to find
76// memory usage issues sooner.
77#define MEMSET_FREED 1
78
79#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
80
Wink Savillef4c4d362009-04-02 01:37:03 -070081#define MIN(a,b) ((a)<(b) ? (a) : (b))
82
The Android Open Source Project00f06fc2009-03-03 19:32:15 -080083/* Constants for response types */
84#define RESPONSE_SOLICITED 0
85#define RESPONSE_UNSOLICITED 1
86
87/* Negative values for private RIL errno's */
88#define RIL_ERRNO_INVALID_RESPONSE -1
89
90// request, response, and unsolicited msg print macro
91#define PRINTBUF_SIZE 8096
92
93// Enable RILC log
94#define RILC_LOG 0
95
96#if RILC_LOG
97 #define startRequest sprintf(printBuf, "(")
98 #define closeRequest sprintf(printBuf, "%s)", printBuf)
99 #define printRequest(token, req) \
Wink Saville8eb2a122012-11-19 16:05:13 -0800100 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800101
102 #define startResponse sprintf(printBuf, "%s {", printBuf)
103 #define closeResponse sprintf(printBuf, "%s}", printBuf)
Wink Saville8eb2a122012-11-19 16:05:13 -0800104 #define printResponse RLOGD("%s", printBuf)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800105
106 #define clearPrintBuf printBuf[0] = 0
107 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
108 #define appendPrintBuf(x...) sprintf(printBuf, x)
109#else
110 #define startRequest
111 #define closeRequest
112 #define printRequest(token, req)
113 #define startResponse
114 #define closeResponse
115 #define printResponse
116 #define clearPrintBuf
117 #define removeLastChar
118 #define appendPrintBuf(x...)
119#endif
120
121enum WakeType {DONT_WAKE, WAKE_PARTIAL};
122
123typedef struct {
124 int requestNumber;
125 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
126 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
127} CommandInfo;
128
129typedef struct {
130 int requestNumber;
131 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
132 WakeType wakeType;
133} UnsolResponseInfo;
134
135typedef struct RequestInfo {
Wink Saville7f856802009-06-09 10:23:37 -0700136 int32_t token; //this is not RIL_Token
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800137 CommandInfo *pCI;
138 struct RequestInfo *p_next;
139 char cancelled;
140 char local; // responses to local commands do not go back to command process
Etan Cohend3652192014-06-20 08:28:44 -0700141 RIL_SOCKET_ID socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800142} RequestInfo;
143
Wink Saville3d54e742009-05-18 18:00:44 -0700144typedef struct UserCallbackInfo {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800145 RIL_TimedCallback p_callback;
146 void *userParam;
147 struct ril_event event;
148 struct UserCallbackInfo *p_next;
149} UserCallbackInfo;
150
Etan Cohend3652192014-06-20 08:28:44 -0700151typedef struct SocketListenParam {
152 RIL_SOCKET_ID socket_id;
153 int fdListen;
154 int fdCommand;
155 char* processName;
156 struct ril_event* commands_event;
157 struct ril_event* listen_event;
158 void (*processCommandsCallback)(int fd, short flags, void *param);
159 RecordStream *p_rs;
160} SocketListenParam;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700161
Etan Cohend3652192014-06-20 08:28:44 -0700162extern "C" const char * requestToString(int request);
163extern "C" const char * failCauseToString(RIL_Errno);
164extern "C" const char * callStateToString(RIL_CallState);
165extern "C" const char * radioStateToString(RIL_RadioState);
166extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
167
168extern "C"
169char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800170/*******************************************************************/
171
172RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
173static int s_registerCalled = 0;
174
175static pthread_t s_tid_dispatch;
176static pthread_t s_tid_reader;
177static int s_started = 0;
178
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800179static int s_fdDebug = -1;
Etan Cohend3652192014-06-20 08:28:44 -0700180static int s_fdDebug_socket2 = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800181
182static int s_fdWakeupRead;
183static int s_fdWakeupWrite;
184
185static struct ril_event s_commands_event;
186static struct ril_event s_wakeupfd_event;
187static struct ril_event s_listen_event;
Etan Cohend3652192014-06-20 08:28:44 -0700188static SocketListenParam s_ril_param_socket;
189
190static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
191static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
192static RequestInfo *s_pendingRequests = NULL;
193
194#if (SIM_COUNT >= 2)
195static struct ril_event s_commands_event_socket2;
196static struct ril_event s_listen_event_socket2;
197static SocketListenParam s_ril_param_socket2;
198
199static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
200static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
201static RequestInfo *s_pendingRequests_socket2 = NULL;
202#endif
203
204#if (SIM_COUNT >= 3)
205static struct ril_event s_commands_event_socket3;
206static struct ril_event s_listen_event_socket3;
207static SocketListenParam s_ril_param_socket3;
208
209static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
210static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
211static RequestInfo *s_pendingRequests_socket3 = NULL;
212#endif
213
214#if (SIM_COUNT >= 4)
215static struct ril_event s_commands_event_socket4;
216static struct ril_event s_listen_event_socket4;
217static SocketListenParam s_ril_param_socket4;
218
219static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
220static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
221static RequestInfo *s_pendingRequests_socket4 = NULL;
222#endif
223
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800224static struct ril_event s_wake_timeout_event;
225static struct ril_event s_debug_event;
226
227
228static const struct timeval TIMEVAL_WAKE_TIMEOUT = {1,0};
229
Etan Cohend3652192014-06-20 08:28:44 -0700230
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800231static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
232static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
233
234static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
235static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
236
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800237static RequestInfo *s_toDispatchHead = NULL;
238static RequestInfo *s_toDispatchTail = NULL;
239
240static UserCallbackInfo *s_last_wake_timeout_info = NULL;
241
242static void *s_lastNITZTimeData = NULL;
243static size_t s_lastNITZTimeDataSize;
244
245#if RILC_LOG
246 static char printBuf[PRINTBUF_SIZE];
247#endif
248
249/*******************************************************************/
Etan Cohend3652192014-06-20 08:28:44 -0700250static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800251
252static void dispatchVoid (Parcel& p, RequestInfo *pRI);
253static void dispatchString (Parcel& p, RequestInfo *pRI);
254static void dispatchStrings (Parcel& p, RequestInfo *pRI);
255static void dispatchInts (Parcel& p, RequestInfo *pRI);
256static void dispatchDial (Parcel& p, RequestInfo *pRI);
257static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800258static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800259static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
260static void dispatchRaw(Parcel& p, RequestInfo *pRI);
261static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -0700262static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800263static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Sungmin Choi75697532013-04-26 15:04:45 -0700264static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800265static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800266
Wink Savillef4c4d362009-04-02 01:37:03 -0700267static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -0700268static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
269static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
270static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Wink Savillef4c4d362009-04-02 01:37:03 -0700271static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
Wink Savillea592eeb2009-05-22 13:26:36 -0700272static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
Wink Savillef4c4d362009-04-02 01:37:03 -0700273static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
274static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Jake Hamby8a4a2332014-01-15 13:12:05 -0800275static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
276static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
Etan Cohend3652192014-06-20 08:28:44 -0700277static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
Amit Mahajan90530a62014-07-01 15:54:08 -0700278static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
Amit Mahajanc796e222014-08-13 16:54:01 +0000279static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700280static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800281static int responseInts(Parcel &p, void *response, size_t responselen);
282static int responseStrings(Parcel &p, void *response, size_t responselen);
283static int responseString(Parcel &p, void *response, size_t responselen);
284static int responseVoid(Parcel &p, void *response, size_t responselen);
285static int responseCallList(Parcel &p, void *response, size_t responselen);
286static int responseSMS(Parcel &p, void *response, size_t responselen);
287static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
288static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700289static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800290static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800291static int responseRaw(Parcel &p, void *response, size_t responselen);
292static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700294static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
295static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700296static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800297static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700298static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
299static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
300static int responseCallRing(Parcel &p, void *response, size_t responselen);
301static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
302static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800303static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700304static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700305static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
Wink Savillec29360a2014-07-13 05:17:28 -0700306static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Wink Saville8b4e4f72014-10-17 15:01:45 -0700307static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800308static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
309static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
310static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
311
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800312#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700313#if defined(ANDROID_MULTI_SIM)
314extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
315 size_t datalen, RIL_SOCKET_ID socket_id);
316#else
Wink Saville7f856802009-06-09 10:23:37 -0700317extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800318 size_t datalen);
319#endif
Etan Cohend3652192014-06-20 08:28:44 -0700320#endif
321
322#if defined(ANDROID_MULTI_SIM)
323#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
324#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
325#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
326#else
327#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
328#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
329#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
330#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331
Wink Saville7f856802009-06-09 10:23:37 -0700332static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700333 (RIL_TimedCallback callback, void *param,
334 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800335
336/** Index == requestNumber */
337static CommandInfo s_commands[] = {
338#include "ril_commands.h"
339};
340
341static UnsolResponseInfo s_unsolResponses[] = {
342#include "ril_unsol_commands.h"
343};
344
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800345/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
346 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
347 radio state message and store it. Every time there is a change in Radio State
348 check to see if voice radio tech changes and notify telephony
349 */
350int voiceRadioTech = -1;
351
352/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
353 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
354 source from radio state and store it. Every time there is a change in Radio State
355 check to see if subscription source changed and notify telephony
356 */
357int cdmaSubscriptionSource = -1;
358
359/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
360 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
361 check to see if SIM/RUIM status changed and notify telephony
362 */
363int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800364
Etan Cohend3652192014-06-20 08:28:44 -0700365static char * RIL_getRilSocketName() {
366 return rild;
367}
368
369extern "C"
370void RIL_setRilSocketName(char * s) {
371 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
372}
373
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800374static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700375strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800376 size_t stringlen;
377 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700378
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800379 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700380
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800381 return strndup16to8(s16, stringlen);
382}
383
Wink Saville8b4e4f72014-10-17 15:01:45 -0700384static status_t
385readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
386 size_t s16Len;
387 const char16_t *s16;
388
389 s16 = p.readString16Inplace(&s16Len);
390 if (s16 == NULL) {
391 return NO_MEMORY;
392 }
393 size_t strLen = strnlen16to8(s16, s16Len);
394 if ((strLen + 1) > maxLen) {
395 return NO_MEMORY;
396 }
397 if (strncpy16to8(str, s16, strLen) == NULL) {
398 return NO_MEMORY;
399 } else {
400 return NO_ERROR;
401 }
402}
403
Wink Savillef4c4d362009-04-02 01:37:03 -0700404static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800405 char16_t *s16;
406 size_t s16_len;
407 s16 = strdup8to16(s, &s16_len);
408 p.writeString16(s16, s16_len);
409 free(s16);
410}
411
412
413static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700414memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800415 if (s != NULL) {
416 memset (s, 0, strlen(s));
417 }
418}
419
420void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
421 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700422 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800423 // do nothing -- the data reference lives longer than the Parcel object
424}
425
Wink Saville7f856802009-06-09 10:23:37 -0700426/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800427 * To be called from dispatch thread
428 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700429 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430 */
431static void
Etan Cohend3652192014-06-20 08:28:44 -0700432issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800433 RequestInfo *pRI;
434 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700435 /* Hook for current context */
436 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
437 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
438 /* pendingRequestsHook refer to &s_pendingRequests */
439 RequestInfo** pendingRequestsHook = &s_pendingRequests;
440
441#if (SIM_COUNT == 2)
442 if (socket_id == RIL_SOCKET_2) {
443 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
444 pendingRequestsHook = &s_pendingRequests_socket2;
445 }
446#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800447
448 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
449
450 pRI->local = 1;
451 pRI->token = 0xffffffff; // token is not used in this context
452 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700453 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800454
Etan Cohend3652192014-06-20 08:28:44 -0700455 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800456 assert (ret == 0);
457
Etan Cohend3652192014-06-20 08:28:44 -0700458 pRI->p_next = *pendingRequestsHook;
459 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460
Etan Cohend3652192014-06-20 08:28:44 -0700461 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800462 assert (ret == 0);
463
Wink Saville8eb2a122012-11-19 16:05:13 -0800464 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800465
Etan Cohend3652192014-06-20 08:28:44 -0700466 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800467}
468
469
470
471static int
Etan Cohend3652192014-06-20 08:28:44 -0700472processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800473 Parcel p;
474 status_t status;
475 int32_t request;
476 int32_t token;
477 RequestInfo *pRI;
478 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700479 /* Hook for current context */
480 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
481 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
482 /* pendingRequestsHook refer to &s_pendingRequests */
483 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800484
485 p.setData((uint8_t *) buffer, buflen);
486
487 // status checked at end
488 status = p.readInt32(&request);
489 status = p.readInt32 (&token);
490
Etan Cohend3652192014-06-20 08:28:44 -0700491#if (SIM_COUNT >= 2)
492 if (socket_id == RIL_SOCKET_2) {
493 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
494 pendingRequestsHook = &s_pendingRequests_socket2;
495 }
496#if (SIM_COUNT >= 3)
497 else if (socket_id == RIL_SOCKET_3) {
498 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
499 pendingRequestsHook = &s_pendingRequests_socket3;
500 }
501#endif
502#if (SIM_COUNT >= 4)
503 else if (socket_id == RIL_SOCKET_4) {
504 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
505 pendingRequestsHook = &s_pendingRequests_socket4;
506 }
507#endif
508#endif
509
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800510 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800511 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800512 return 0;
513 }
514
515 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700516 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800517 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800518 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700519 pErr.writeInt32 (RESPONSE_SOLICITED);
520 pErr.writeInt32 (token);
521 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
522
523 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800524 return 0;
525 }
526
527
528 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
529
530 pRI->token = token;
531 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700532 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800533
Etan Cohend3652192014-06-20 08:28:44 -0700534 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800535 assert (ret == 0);
536
Etan Cohend3652192014-06-20 08:28:44 -0700537 pRI->p_next = *pendingRequestsHook;
538 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800539
Etan Cohend3652192014-06-20 08:28:44 -0700540 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800541 assert (ret == 0);
542
543/* sLastDispatchedToken = token; */
544
Wink Saville7f856802009-06-09 10:23:37 -0700545 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800546
547 return 0;
548}
549
550static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700551invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800552 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800553 pRI->token, requestToString(pRI->pCI->requestNumber));
554}
555
556/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700557static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700558dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559 clearPrintBuf;
560 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700561 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800562}
563
564/** Callee expects const char * */
565static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700566dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800567 status_t status;
568 size_t datalen;
569 size_t stringlen;
570 char *string8 = NULL;
571
572 string8 = strdupReadString(p);
573
574 startRequest;
575 appendPrintBuf("%s%s", printBuf, string8);
576 closeRequest;
577 printRequest(pRI->token, pRI->pCI->requestNumber);
578
Etan Cohend3652192014-06-20 08:28:44 -0700579 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
580 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800581
582#ifdef MEMSET_FREED
583 memsetString(string8);
584#endif
585
586 free(string8);
587 return;
588invalid:
589 invalidCommandBlock(pRI);
590 return;
591}
592
593/** Callee expects const char ** */
594static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700595dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800596 int32_t countStrings;
597 status_t status;
598 size_t datalen;
599 char **pStrings;
600
601 status = p.readInt32 (&countStrings);
602
603 if (status != NO_ERROR) {
604 goto invalid;
605 }
606
607 startRequest;
608 if (countStrings == 0) {
609 // just some non-null pointer
610 pStrings = (char **)alloca(sizeof(char *));
611 datalen = 0;
612 } else if (((int)countStrings) == -1) {
613 pStrings = NULL;
614 datalen = 0;
615 } else {
616 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700617
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800618 pStrings = (char **)alloca(datalen);
619
620 for (int i = 0 ; i < countStrings ; i++) {
621 pStrings[i] = strdupReadString(p);
622 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
623 }
624 }
625 removeLastChar;
626 closeRequest;
627 printRequest(pRI->token, pRI->pCI->requestNumber);
628
Etan Cohend3652192014-06-20 08:28:44 -0700629 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800630
631 if (pStrings != NULL) {
632 for (int i = 0 ; i < countStrings ; i++) {
633#ifdef MEMSET_FREED
634 memsetString (pStrings[i]);
635#endif
636 free(pStrings[i]);
637 }
638
639#ifdef MEMSET_FREED
640 memset(pStrings, 0, datalen);
641#endif
642 }
Wink Saville7f856802009-06-09 10:23:37 -0700643
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800644 return;
645invalid:
646 invalidCommandBlock(pRI);
647 return;
648}
649
650/** Callee expects const int * */
651static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700652dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800653 int32_t count;
654 status_t status;
655 size_t datalen;
656 int *pInts;
657
658 status = p.readInt32 (&count);
659
660 if (status != NO_ERROR || count == 0) {
661 goto invalid;
662 }
663
664 datalen = sizeof(int) * count;
665 pInts = (int *)alloca(datalen);
666
667 startRequest;
668 for (int i = 0 ; i < count ; i++) {
669 int32_t t;
670
671 status = p.readInt32(&t);
672 pInts[i] = (int)t;
673 appendPrintBuf("%s%d,", printBuf, t);
674
675 if (status != NO_ERROR) {
676 goto invalid;
677 }
678 }
679 removeLastChar;
680 closeRequest;
681 printRequest(pRI->token, pRI->pCI->requestNumber);
682
Etan Cohend3652192014-06-20 08:28:44 -0700683 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
684 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800685
686#ifdef MEMSET_FREED
687 memset(pInts, 0, datalen);
688#endif
689
690 return;
691invalid:
692 invalidCommandBlock(pRI);
693 return;
694}
695
696
Wink Saville7f856802009-06-09 10:23:37 -0700697/**
698 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800699 * Payload is:
700 * int32_t status
701 * String pdu
702 */
703static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700704dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800705 RIL_SMS_WriteArgs args;
706 int32_t t;
707 status_t status;
708
709 memset (&args, 0, sizeof(args));
710
711 status = p.readInt32(&t);
712 args.status = (int)t;
713
714 args.pdu = strdupReadString(p);
715
716 if (status != NO_ERROR || args.pdu == NULL) {
717 goto invalid;
718 }
719
720 args.smsc = strdupReadString(p);
721
722 startRequest;
723 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
724 (char*)args.pdu, (char*)args.smsc);
725 closeRequest;
726 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700727
Etan Cohend3652192014-06-20 08:28:44 -0700728 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800729
730#ifdef MEMSET_FREED
731 memsetString (args.pdu);
732#endif
733
734 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700735
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800736#ifdef MEMSET_FREED
737 memset(&args, 0, sizeof(args));
738#endif
739
740 return;
741invalid:
742 invalidCommandBlock(pRI);
743 return;
744}
745
Wink Saville7f856802009-06-09 10:23:37 -0700746/**
747 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800748 * Payload is:
749 * String address
750 * int32_t clir
751 */
752static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700753dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800754 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800755 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800756 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800757 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800758 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800759 status_t status;
760
761 memset (&dial, 0, sizeof(dial));
762
763 dial.address = strdupReadString(p);
764
765 status = p.readInt32(&t);
766 dial.clir = (int)t;
767
768 if (status != NO_ERROR || dial.address == NULL) {
769 goto invalid;
770 }
771
Wink Saville3a4840b2010-04-07 13:29:58 -0700772 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800773 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800774 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800775 } else {
776 status = p.readInt32(&uusPresent);
777
778 if (status != NO_ERROR) {
779 goto invalid;
780 }
781
782 if (uusPresent == 0) {
783 dial.uusInfo = NULL;
784 } else {
785 int32_t len;
786
787 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
788
789 status = p.readInt32(&t);
790 uusInfo.uusType = (RIL_UUS_Type) t;
791
792 status = p.readInt32(&t);
793 uusInfo.uusDcs = (RIL_UUS_DCS) t;
794
795 status = p.readInt32(&len);
796 if (status != NO_ERROR) {
797 goto invalid;
798 }
799
800 // The java code writes -1 for null arrays
801 if (((int) len) == -1) {
802 uusInfo.uusData = NULL;
803 len = 0;
804 } else {
805 uusInfo.uusData = (char*) p.readInplace(len);
806 }
807
808 uusInfo.uusLength = len;
809 dial.uusInfo = &uusInfo;
810 }
Wink Saville7bce0822010-01-08 15:20:12 -0800811 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800812 }
813
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800814 startRequest;
815 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800816 if (uusPresent) {
817 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
818 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
819 dial.uusInfo->uusLength);
820 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800821 closeRequest;
822 printRequest(pRI->token, pRI->pCI->requestNumber);
823
Etan Cohend3652192014-06-20 08:28:44 -0700824 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800825
826#ifdef MEMSET_FREED
827 memsetString (dial.address);
828#endif
829
830 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700831
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800832#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800833 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800834 memset(&dial, 0, sizeof(dial));
835#endif
836
837 return;
838invalid:
839 invalidCommandBlock(pRI);
840 return;
841}
842
Wink Saville7f856802009-06-09 10:23:37 -0700843/**
844 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800845 * Payload is:
846 * int32_t command
847 * int32_t fileid
848 * String path
849 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700850 * String data
851 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800852 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800853 */
854static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700855dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800856 union RIL_SIM_IO {
857 RIL_SIM_IO_v6 v6;
858 RIL_SIM_IO_v5 v5;
859 } simIO;
860
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800861 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800862 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863 status_t status;
864
865 memset (&simIO, 0, sizeof(simIO));
866
Wink Saville7f856802009-06-09 10:23:37 -0700867 // note we only check status at the end
868
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800869 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800870 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800871
872 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800873 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800874
Wink Savillec0114b32011-02-18 10:14:07 -0800875 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876
877 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800878 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800879
880 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800881 simIO.v6.p2 = (int)t;
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.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800885
Wink Savillec0114b32011-02-18 10:14:07 -0800886 simIO.v6.data = strdupReadString(p);
887 simIO.v6.pin2 = strdupReadString(p);
888 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800889
890 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800891 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
892 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
893 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
894 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800895 closeRequest;
896 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700897
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800898 if (status != NO_ERROR) {
899 goto invalid;
900 }
901
Wink Savillec0114b32011-02-18 10:14:07 -0800902 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700903 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800904
905#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800906 memsetString (simIO.v6.path);
907 memsetString (simIO.v6.data);
908 memsetString (simIO.v6.pin2);
909 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800910#endif
911
Wink Savillec0114b32011-02-18 10:14:07 -0800912 free (simIO.v6.path);
913 free (simIO.v6.data);
914 free (simIO.v6.pin2);
915 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700916
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800917#ifdef MEMSET_FREED
918 memset(&simIO, 0, sizeof(simIO));
919#endif
920
921 return;
922invalid:
923 invalidCommandBlock(pRI);
924 return;
925}
926
927/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800928 * Callee expects const RIL_SIM_APDU *
929 * Payload is:
930 * int32_t sessionid
931 * int32_t cla
932 * int32_t instruction
933 * int32_t p1, p2, p3
934 * String data
935 */
936static void
937dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
938 int32_t t;
939 status_t status;
940 RIL_SIM_APDU apdu;
941
942 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
943
944 // Note we only check status at the end. Any single failure leads to
945 // subsequent reads filing.
946 status = p.readInt32(&t);
947 apdu.sessionid = (int)t;
948
949 status = p.readInt32(&t);
950 apdu.cla = (int)t;
951
952 status = p.readInt32(&t);
953 apdu.instruction = (int)t;
954
955 status = p.readInt32(&t);
956 apdu.p1 = (int)t;
957
958 status = p.readInt32(&t);
959 apdu.p2 = (int)t;
960
961 status = p.readInt32(&t);
962 apdu.p3 = (int)t;
963
964 apdu.data = strdupReadString(p);
965
966 startRequest;
967 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
968 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
969 apdu.p3, (char*)apdu.data);
970 closeRequest;
971 printRequest(pRI->token, pRI->pCI->requestNumber);
972
973 if (status != NO_ERROR) {
974 goto invalid;
975 }
976
Etan Cohend3652192014-06-20 08:28:44 -0700977 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800978
979#ifdef MEMSET_FREED
980 memsetString(apdu.data);
981#endif
982 free(apdu.data);
983
984#ifdef MEMSET_FREED
985 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
986#endif
987
988 return;
989invalid:
990 invalidCommandBlock(pRI);
991 return;
992}
993
994
995/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800996 * Callee expects const RIL_CallForwardInfo *
997 * Payload is:
998 * int32_t status/action
999 * int32_t reason
1000 * int32_t serviceCode
1001 * int32_t toa
1002 * String number (0 length -> null)
1003 * int32_t timeSeconds
1004 */
Wink Saville7f856802009-06-09 10:23:37 -07001005static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001006dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001007 RIL_CallForwardInfo cff;
1008 int32_t t;
1009 status_t status;
1010
1011 memset (&cff, 0, sizeof(cff));
1012
Wink Saville7f856802009-06-09 10:23:37 -07001013 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001014
1015 status = p.readInt32(&t);
1016 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -07001017
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001018 status = p.readInt32(&t);
1019 cff.reason = (int)t;
1020
1021 status = p.readInt32(&t);
1022 cff.serviceClass = (int)t;
1023
1024 status = p.readInt32(&t);
1025 cff.toa = (int)t;
1026
1027 cff.number = strdupReadString(p);
1028
1029 status = p.readInt32(&t);
1030 cff.timeSeconds = (int)t;
1031
1032 if (status != NO_ERROR) {
1033 goto invalid;
1034 }
1035
1036 // special case: number 0-length fields is null
1037
1038 if (cff.number != NULL && strlen (cff.number) == 0) {
1039 cff.number = NULL;
1040 }
1041
1042 startRequest;
1043 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1044 cff.status, cff.reason, cff.serviceClass, cff.toa,
1045 (char*)cff.number, cff.timeSeconds);
1046 closeRequest;
1047 printRequest(pRI->token, pRI->pCI->requestNumber);
1048
Etan Cohend3652192014-06-20 08:28:44 -07001049 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001050
1051#ifdef MEMSET_FREED
1052 memsetString(cff.number);
1053#endif
1054
1055 free (cff.number);
1056
1057#ifdef MEMSET_FREED
1058 memset(&cff, 0, sizeof(cff));
1059#endif
1060
1061 return;
1062invalid:
1063 invalidCommandBlock(pRI);
1064 return;
1065}
1066
1067
Wink Saville7f856802009-06-09 10:23:37 -07001068static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001069dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001070 int32_t len;
1071 status_t status;
1072 const void *data;
1073
1074 status = p.readInt32(&len);
1075
1076 if (status != NO_ERROR) {
1077 goto invalid;
1078 }
1079
1080 // The java code writes -1 for null arrays
1081 if (((int)len) == -1) {
1082 data = NULL;
1083 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001084 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001085
1086 data = p.readInplace(len);
1087
1088 startRequest;
1089 appendPrintBuf("%sraw_size=%d", printBuf, len);
1090 closeRequest;
1091 printRequest(pRI->token, pRI->pCI->requestNumber);
1092
Etan Cohend3652192014-06-20 08:28:44 -07001093 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001094
1095 return;
1096invalid:
1097 invalidCommandBlock(pRI);
1098 return;
1099}
1100
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001101static status_t
1102constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001103 int32_t t;
1104 uint8_t ut;
1105 status_t status;
1106 int32_t digitCount;
1107 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001108
Wink Savillef4c4d362009-04-02 01:37:03 -07001109 memset(&rcsm, 0, sizeof(rcsm));
1110
1111 status = p.readInt32(&t);
1112 rcsm.uTeleserviceID = (int) t;
1113
1114 status = p.read(&ut,sizeof(ut));
1115 rcsm.bIsServicePresent = (uint8_t) ut;
1116
1117 status = p.readInt32(&t);
1118 rcsm.uServicecategory = (int) t;
1119
1120 status = p.readInt32(&t);
1121 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1122
1123 status = p.readInt32(&t);
1124 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1125
1126 status = p.readInt32(&t);
1127 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1128
1129 status = p.readInt32(&t);
1130 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1131
1132 status = p.read(&ut,sizeof(ut));
1133 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1134
1135 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1136 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1137 status = p.read(&ut,sizeof(ut));
1138 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1139 }
1140
Wink Saville7f856802009-06-09 10:23:37 -07001141 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001142 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1143
Wink Saville7f856802009-06-09 10:23:37 -07001144 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001145 rcsm.sSubAddress.odd = (uint8_t) ut;
1146
1147 status = p.read(&ut,sizeof(ut));
1148 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1149
1150 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001151 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1152 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001153 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1154 }
1155
Wink Saville7f856802009-06-09 10:23:37 -07001156 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001157 rcsm.uBearerDataLen = (int) t;
1158
1159 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001160 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1161 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001162 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1163 }
1164
1165 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001166 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001167 }
1168
1169 startRequest;
1170 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001171 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001172 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001173 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001174 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001175
Wink Savillef4c4d362009-04-02 01:37:03 -07001176 printRequest(pRI->token, pRI->pCI->requestNumber);
1177
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001178 return status;
1179}
1180
1181static void
1182dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1183 RIL_CDMA_SMS_Message rcsm;
1184
1185 ALOGD("dispatchCdmaSms");
1186 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1187 goto invalid;
1188 }
1189
Etan Cohend3652192014-06-20 08:28:44 -07001190 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001191
1192#ifdef MEMSET_FREED
1193 memset(&rcsm, 0, sizeof(rcsm));
1194#endif
1195
1196 return;
1197
1198invalid:
1199 invalidCommandBlock(pRI);
1200 return;
1201}
1202
Wink Saville7f856802009-06-09 10:23:37 -07001203static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001204dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1205 RIL_IMS_SMS_Message rism;
1206 RIL_CDMA_SMS_Message rcsm;
1207
1208 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1209
1210 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1211 goto invalid;
1212 }
1213 memset(&rism, 0, sizeof(rism));
1214 rism.tech = RADIO_TECH_3GPP2;
1215 rism.retry = retry;
1216 rism.messageRef = messageRef;
1217 rism.message.cdmaMessage = &rcsm;
1218
Etan Cohend3652192014-06-20 08:28:44 -07001219 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001220 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001221 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001222
1223#ifdef MEMSET_FREED
1224 memset(&rcsm, 0, sizeof(rcsm));
1225 memset(&rism, 0, sizeof(rism));
1226#endif
1227
1228 return;
1229
1230invalid:
1231 invalidCommandBlock(pRI);
1232 return;
1233}
1234
1235static void
1236dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1237 RIL_IMS_SMS_Message rism;
1238 int32_t countStrings;
1239 status_t status;
1240 size_t datalen;
1241 char **pStrings;
1242 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1243
1244 status = p.readInt32 (&countStrings);
1245
1246 if (status != NO_ERROR) {
1247 goto invalid;
1248 }
1249
1250 memset(&rism, 0, sizeof(rism));
1251 rism.tech = RADIO_TECH_3GPP;
1252 rism.retry = retry;
1253 rism.messageRef = messageRef;
1254
1255 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001256 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1257 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001258 if (countStrings == 0) {
1259 // just some non-null pointer
1260 pStrings = (char **)alloca(sizeof(char *));
1261 datalen = 0;
1262 } else if (((int)countStrings) == -1) {
1263 pStrings = NULL;
1264 datalen = 0;
1265 } else {
1266 datalen = sizeof(char *) * countStrings;
1267
1268 pStrings = (char **)alloca(datalen);
1269
1270 for (int i = 0 ; i < countStrings ; i++) {
1271 pStrings[i] = strdupReadString(p);
1272 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1273 }
1274 }
1275 removeLastChar;
1276 closeRequest;
1277 printRequest(pRI->token, pRI->pCI->requestNumber);
1278
1279 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001280 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001281 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001282 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001283
1284 if (pStrings != NULL) {
1285 for (int i = 0 ; i < countStrings ; i++) {
1286#ifdef MEMSET_FREED
1287 memsetString (pStrings[i]);
1288#endif
1289 free(pStrings[i]);
1290 }
1291
1292#ifdef MEMSET_FREED
1293 memset(pStrings, 0, datalen);
1294#endif
1295 }
1296
1297#ifdef MEMSET_FREED
1298 memset(&rism, 0, sizeof(rism));
1299#endif
1300 return;
1301invalid:
1302 ALOGE("dispatchImsGsmSms invalid block");
1303 invalidCommandBlock(pRI);
1304 return;
1305}
1306
1307static void
1308dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1309 int32_t t;
1310 status_t status = p.readInt32(&t);
1311 RIL_RadioTechnologyFamily format;
1312 uint8_t retry;
1313 int32_t messageRef;
1314
1315 ALOGD("dispatchImsSms");
1316 if (status != NO_ERROR) {
1317 goto invalid;
1318 }
1319 format = (RIL_RadioTechnologyFamily) t;
1320
1321 // read retry field
1322 status = p.read(&retry,sizeof(retry));
1323 if (status != NO_ERROR) {
1324 goto invalid;
1325 }
1326 // read messageRef field
1327 status = p.read(&messageRef,sizeof(messageRef));
1328 if (status != NO_ERROR) {
1329 goto invalid;
1330 }
1331
1332 if (RADIO_TECH_3GPP == format) {
1333 dispatchImsGsmSms(p, pRI, retry, messageRef);
1334 } else if (RADIO_TECH_3GPP2 == format) {
1335 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1336 } else {
1337 ALOGE("requestImsSendSMS invalid format value =%d", format);
1338 }
1339
1340 return;
1341
1342invalid:
1343 invalidCommandBlock(pRI);
1344 return;
1345}
1346
1347static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001348dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1349 RIL_CDMA_SMS_Ack rcsa;
1350 int32_t t;
1351 status_t status;
1352 int32_t digitCount;
1353
1354 memset(&rcsa, 0, sizeof(rcsa));
1355
1356 status = p.readInt32(&t);
1357 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1358
1359 status = p.readInt32(&t);
1360 rcsa.uSMSCauseCode = (int) t;
1361
1362 if (status != NO_ERROR) {
1363 goto invalid;
1364 }
1365
1366 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001367 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1368 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001369 closeRequest;
1370
1371 printRequest(pRI->token, pRI->pCI->requestNumber);
1372
Etan Cohend3652192014-06-20 08:28:44 -07001373 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001374
1375#ifdef MEMSET_FREED
1376 memset(&rcsa, 0, sizeof(rcsa));
1377#endif
1378
1379 return;
1380
1381invalid:
1382 invalidCommandBlock(pRI);
1383 return;
1384}
1385
Wink Savillea592eeb2009-05-22 13:26:36 -07001386static void
1387dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1388 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001389 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001390 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001391
Wink Savillea592eeb2009-05-22 13:26:36 -07001392 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001393 if (status != NO_ERROR) {
1394 goto invalid;
1395 }
1396
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001397 {
1398 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1399 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001400
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001401 startRequest;
1402 for (int i = 0 ; i < num ; i++ ) {
1403 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001404
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001405 status = p.readInt32(&t);
1406 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001407
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001408 status = p.readInt32(&t);
1409 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001410
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001411 status = p.readInt32(&t);
1412 gsmBci[i].fromCodeScheme = (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].toCodeScheme = (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].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001419
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001420 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1421 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1422 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1423 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1424 gsmBci[i].selected);
1425 }
1426 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001428 if (status != NO_ERROR) {
1429 goto invalid;
1430 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001431
Etan Cohend3652192014-06-20 08:28:44 -07001432 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001433 gsmBciPtrs,
1434 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001435 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001436
1437#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001438 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1439 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001440#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001441 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001442
1443 return;
1444
1445invalid:
1446 invalidCommandBlock(pRI);
1447 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001448}
Wink Savillef4c4d362009-04-02 01:37:03 -07001449
Wink Savillea592eeb2009-05-22 13:26:36 -07001450static void
1451dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1452 int32_t t;
1453 status_t status;
1454 int32_t num;
1455
1456 status = p.readInt32(&num);
1457 if (status != NO_ERROR) {
1458 goto invalid;
1459 }
1460
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001461 {
1462 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1463 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001464
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001465 startRequest;
1466 for (int i = 0 ; i < num ; i++ ) {
1467 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001468
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001469 status = p.readInt32(&t);
1470 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001471
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001472 status = p.readInt32(&t);
1473 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001474
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 status = p.readInt32(&t);
1476 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001477
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001478 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1479 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1480 cdmaBci[i].language, cdmaBci[i].selected);
1481 }
1482 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001483
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001484 if (status != NO_ERROR) {
1485 goto invalid;
1486 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001487
Etan Cohend3652192014-06-20 08:28:44 -07001488 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001489 cdmaBciPtrs,
1490 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001491 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001492
1493#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001494 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1495 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001496#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001497 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001498
1499 return;
1500
1501invalid:
1502 invalidCommandBlock(pRI);
1503 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001504}
1505
1506static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1507 RIL_CDMA_SMS_WriteArgs rcsw;
1508 int32_t t;
1509 uint32_t ut;
1510 uint8_t uct;
1511 status_t status;
1512 int32_t digitCount;
1513
1514 memset(&rcsw, 0, sizeof(rcsw));
1515
1516 status = p.readInt32(&t);
1517 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001518
Wink Savillef4c4d362009-04-02 01:37:03 -07001519 status = p.readInt32(&t);
1520 rcsw.message.uTeleserviceID = (int) t;
1521
1522 status = p.read(&uct,sizeof(uct));
1523 rcsw.message.bIsServicePresent = (uint8_t) uct;
1524
1525 status = p.readInt32(&t);
1526 rcsw.message.uServicecategory = (int) t;
1527
1528 status = p.readInt32(&t);
1529 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1530
1531 status = p.readInt32(&t);
1532 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1533
1534 status = p.readInt32(&t);
1535 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1536
1537 status = p.readInt32(&t);
1538 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1539
1540 status = p.read(&uct,sizeof(uct));
1541 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1542
1543 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1544 status = p.read(&uct,sizeof(uct));
1545 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1546 }
1547
Wink Savillea592eeb2009-05-22 13:26:36 -07001548 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001549 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1550
Wink Savillea592eeb2009-05-22 13:26:36 -07001551 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001552 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1553
1554 status = p.read(&uct,sizeof(uct));
1555 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1556
1557 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001558 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001559 rcsw.message.sSubAddress.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.uBearerDataLen = (int) t;
1564
1565 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001566 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001567 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1568 }
1569
1570 if (status != NO_ERROR) {
1571 goto invalid;
1572 }
1573
1574 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001575 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1576 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1577 message.sAddress.number_mode=%d, \
1578 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001579 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001580 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1581 rcsw.message.sAddress.number_mode,
1582 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001583 closeRequest;
1584
1585 printRequest(pRI->token, pRI->pCI->requestNumber);
1586
Etan Cohend3652192014-06-20 08:28:44 -07001587 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001588
1589#ifdef MEMSET_FREED
1590 memset(&rcsw, 0, sizeof(rcsw));
1591#endif
1592
1593 return;
1594
1595invalid:
1596 invalidCommandBlock(pRI);
1597 return;
1598
1599}
1600
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001601// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1602// Version 4 of the RIL interface adds a new PDP type parameter to support
1603// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1604// RIL, remove the parameter from the request.
1605static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1606 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1607 const int numParamsRilV3 = 6;
1608
1609 // The first bytes of the RIL parcel contain the request number and the
1610 // serial number - see processCommandBuffer(). Copy them over too.
1611 int pos = p.dataPosition();
1612
1613 int numParams = p.readInt32();
1614 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1615 Parcel p2;
1616 p2.appendFrom(&p, 0, pos);
1617 p2.writeInt32(numParamsRilV3);
1618 for(int i = 0; i < numParamsRilV3; i++) {
1619 p2.writeString16(p.readString16());
1620 }
1621 p2.setDataPosition(pos);
1622 dispatchStrings(p2, pRI);
1623 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001624 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001625 dispatchStrings(p, pRI);
1626 }
1627}
1628
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001629// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1630// When all RILs handle this request, this function can be removed and
1631// the request can be sent directly to the RIL using dispatchVoid.
1632static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001633 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001634
1635 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1636 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1637 }
1638
1639 // RILs that support RADIO_STATE_ON should support this request.
1640 if (RADIO_STATE_ON == state) {
1641 dispatchVoid(p, pRI);
1642 return;
1643 }
1644
1645 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1646 // will not support this new request either and decode Voice Radio Technology
1647 // from Radio State
1648 voiceRadioTech = decodeVoiceRadioTechnology(state);
1649
1650 if (voiceRadioTech < 0)
1651 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1652 else
1653 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1654}
1655
1656// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1657// When all RILs handle this request, this function can be removed and
1658// the request can be sent directly to the RIL using dispatchVoid.
1659static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001660 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001661
1662 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1663 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1664 }
1665
1666 // RILs that support RADIO_STATE_ON should support this request.
1667 if (RADIO_STATE_ON == state) {
1668 dispatchVoid(p, pRI);
1669 return;
1670 }
1671
1672 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1673 // will not support this new request either and decode CDMA Subscription Source
1674 // from Radio State
1675 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1676
1677 if (cdmaSubscriptionSource < 0)
1678 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1679 else
1680 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1681}
1682
Sungmin Choi75697532013-04-26 15:04:45 -07001683static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1684{
1685 RIL_InitialAttachApn pf;
1686 int32_t t;
1687 status_t status;
1688
1689 memset(&pf, 0, sizeof(pf));
1690
1691 pf.apn = strdupReadString(p);
1692 pf.protocol = strdupReadString(p);
1693
1694 status = p.readInt32(&t);
1695 pf.authtype = (int) t;
1696
1697 pf.username = strdupReadString(p);
1698 pf.password = strdupReadString(p);
1699
1700 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001701 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1702 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001703 closeRequest;
1704 printRequest(pRI->token, pRI->pCI->requestNumber);
1705
1706 if (status != NO_ERROR) {
1707 goto invalid;
1708 }
Etan Cohend3652192014-06-20 08:28:44 -07001709 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001710
1711#ifdef MEMSET_FREED
1712 memsetString(pf.apn);
1713 memsetString(pf.protocol);
1714 memsetString(pf.username);
1715 memsetString(pf.password);
1716#endif
1717
1718 free(pf.apn);
1719 free(pf.protocol);
1720 free(pf.username);
1721 free(pf.password);
1722
1723#ifdef MEMSET_FREED
1724 memset(&pf, 0, sizeof(pf));
1725#endif
1726
1727 return;
1728invalid:
1729 invalidCommandBlock(pRI);
1730 return;
1731}
1732
Jake Hamby8a4a2332014-01-15 13:12:05 -08001733static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1734 RIL_NV_ReadItem nvri;
1735 int32_t t;
1736 status_t status;
1737
1738 memset(&nvri, 0, sizeof(nvri));
1739
1740 status = p.readInt32(&t);
1741 nvri.itemID = (RIL_NV_Item) t;
1742
1743 if (status != NO_ERROR) {
1744 goto invalid;
1745 }
1746
1747 startRequest;
1748 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1749 closeRequest;
1750
1751 printRequest(pRI->token, pRI->pCI->requestNumber);
1752
Etan Cohend3652192014-06-20 08:28:44 -07001753 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001754
1755#ifdef MEMSET_FREED
1756 memset(&nvri, 0, sizeof(nvri));
1757#endif
1758
1759 return;
1760
1761invalid:
1762 invalidCommandBlock(pRI);
1763 return;
1764}
1765
1766static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1767 RIL_NV_WriteItem nvwi;
1768 int32_t t;
1769 status_t status;
1770
1771 memset(&nvwi, 0, sizeof(nvwi));
1772
1773 status = p.readInt32(&t);
1774 nvwi.itemID = (RIL_NV_Item) t;
1775
1776 nvwi.value = strdupReadString(p);
1777
1778 if (status != NO_ERROR || nvwi.value == NULL) {
1779 goto invalid;
1780 }
1781
1782 startRequest;
1783 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1784 nvwi.value);
1785 closeRequest;
1786
1787 printRequest(pRI->token, pRI->pCI->requestNumber);
1788
Etan Cohend3652192014-06-20 08:28:44 -07001789 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001790
1791#ifdef MEMSET_FREED
1792 memsetString(nvwi.value);
1793#endif
1794
1795 free(nvwi.value);
1796
1797#ifdef MEMSET_FREED
1798 memset(&nvwi, 0, sizeof(nvwi));
1799#endif
1800
1801 return;
1802
1803invalid:
1804 invalidCommandBlock(pRI);
1805 return;
1806}
1807
1808
Etan Cohend3652192014-06-20 08:28:44 -07001809static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1810 RIL_SelectUiccSub uicc_sub;
1811 status_t status;
1812 int32_t t;
1813 memset(&uicc_sub, 0, sizeof(uicc_sub));
1814
1815 status = p.readInt32(&t);
1816 if (status != NO_ERROR) {
1817 goto invalid;
1818 }
1819 uicc_sub.slot = (int) t;
1820
1821 status = p.readInt32(&t);
1822 if (status != NO_ERROR) {
1823 goto invalid;
1824 }
1825 uicc_sub.app_index = (int) t;
1826
1827 status = p.readInt32(&t);
1828 if (status != NO_ERROR) {
1829 goto invalid;
1830 }
1831 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1832
1833 status = p.readInt32(&t);
1834 if (status != NO_ERROR) {
1835 goto invalid;
1836 }
1837 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1838
1839 startRequest;
1840 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1841 uicc_sub.act_status);
1842 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1843 uicc_sub.app_index, uicc_sub.act_status);
1844 closeRequest;
1845 printRequest(pRI->token, pRI->pCI->requestNumber);
1846
1847 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1848
1849#ifdef MEMSET_FREED
1850 memset(&uicc_sub, 0, sizeof(uicc_sub));
1851#endif
1852 return;
1853
1854invalid:
1855 invalidCommandBlock(pRI);
1856 return;
1857}
1858
Amit Mahajan90530a62014-07-01 15:54:08 -07001859static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1860{
1861 RIL_SimAuthentication pf;
1862 int32_t t;
1863 status_t status;
1864
1865 memset(&pf, 0, sizeof(pf));
1866
1867 status = p.readInt32(&t);
1868 pf.authContext = (int) t;
1869 pf.authData = strdupReadString(p);
1870 pf.aid = strdupReadString(p);
1871
1872 startRequest;
1873 appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
1874 closeRequest;
1875 printRequest(pRI->token, pRI->pCI->requestNumber);
1876
1877 if (status != NO_ERROR) {
1878 goto invalid;
1879 }
1880 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1881
1882#ifdef MEMSET_FREED
1883 memsetString(pf.authData);
1884 memsetString(pf.aid);
1885#endif
1886
1887 free(pf.authData);
1888 free(pf.aid);
1889
1890#ifdef MEMSET_FREED
1891 memset(&pf, 0, sizeof(pf));
1892#endif
1893
1894 return;
1895invalid:
1896 invalidCommandBlock(pRI);
1897 return;
1898}
1899
Amit Mahajanc796e222014-08-13 16:54:01 +00001900static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1901 int32_t t;
1902 status_t status;
1903 int32_t num;
1904
1905 status = p.readInt32(&num);
1906 if (status != NO_ERROR) {
1907 goto invalid;
1908 }
1909
1910 {
1911 RIL_DataProfileInfo dataProfiles[num];
1912 RIL_DataProfileInfo *dataProfilePtrs[num];
1913
1914 startRequest;
1915 for (int i = 0 ; i < num ; i++ ) {
1916 dataProfilePtrs[i] = &dataProfiles[i];
1917
1918 status = p.readInt32(&t);
1919 dataProfiles[i].profileId = (int) t;
1920
1921 dataProfiles[i].apn = strdupReadString(p);
1922 dataProfiles[i].protocol = strdupReadString(p);
1923 status = p.readInt32(&t);
1924 dataProfiles[i].authType = (int) t;
1925
1926 dataProfiles[i].user = strdupReadString(p);
1927 dataProfiles[i].password = strdupReadString(p);
1928
1929 status = p.readInt32(&t);
1930 dataProfiles[i].type = (int) t;
1931
1932 status = p.readInt32(&t);
1933 dataProfiles[i].maxConnsTime = (int) t;
1934 status = p.readInt32(&t);
1935 dataProfiles[i].maxConns = (int) t;
1936 status = p.readInt32(&t);
1937 dataProfiles[i].waitTime = (int) t;
1938
1939 status = p.readInt32(&t);
1940 dataProfiles[i].enabled = (int) t;
1941
1942 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
1943 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
1944 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
1945 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
1946 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
1947 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
1948 dataProfiles[i].waitTime, dataProfiles[i].enabled);
1949 }
1950 closeRequest;
1951 printRequest(pRI->token, pRI->pCI->requestNumber);
1952
1953 if (status != NO_ERROR) {
1954 goto invalid;
1955 }
1956 CALL_ONREQUEST(pRI->pCI->requestNumber,
1957 dataProfilePtrs,
1958 num * sizeof(RIL_DataProfileInfo *),
1959 pRI, pRI->socket_id);
1960
1961#ifdef MEMSET_FREED
1962 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
1963 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
1964#endif
1965 }
1966
1967 return;
1968
1969invalid:
1970 invalidCommandBlock(pRI);
1971 return;
1972}
1973
Wink Saville8b4e4f72014-10-17 15:01:45 -07001974static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
1975 RIL_RadioCapability rc;
1976 int32_t t;
1977 status_t status;
1978
1979 memset (&rc, 0, sizeof(RIL_RadioCapability));
1980
1981 status = p.readInt32(&t);
1982 rc.version = (int)t;
1983 if (status != NO_ERROR) {
1984 goto invalid;
1985 }
1986
1987 status = p.readInt32(&t);
1988 rc.session= (int)t;
1989 if (status != NO_ERROR) {
1990 goto invalid;
1991 }
1992
1993 status = p.readInt32(&t);
1994 rc.phase= (int)t;
1995 if (status != NO_ERROR) {
1996 goto invalid;
1997 }
1998
1999 status = p.readInt32(&t);
2000 rc.rat = (int)t;
2001 if (status != NO_ERROR) {
2002 goto invalid;
2003 }
2004
2005 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2006 if (status != NO_ERROR) {
2007 goto invalid;
2008 }
2009
2010 status = p.readInt32(&t);
2011 rc.status = (int)t;
2012
2013 if (status != NO_ERROR) {
2014 goto invalid;
2015 }
2016
2017 startRequest;
2018 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Legler Wu8caf06f2014-10-29 14:02:14 +08002019 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session
2020 rc.phase, rc.rat, rc.logicalModemUuid, rc.session);
Wink Saville8b4e4f72014-10-17 15:01:45 -07002021
2022 closeRequest;
2023 printRequest(pRI->token, pRI->pCI->requestNumber);
2024
2025 CALL_ONREQUEST(pRI->pCI->requestNumber,
2026 &rc,
2027 sizeof(RIL_RadioCapability),
2028 pRI, pRI->socket_id);
2029 return;
2030invalid:
2031 invalidCommandBlock(pRI);
2032 return;
2033}
2034
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002035static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002036blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07002037 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002038 const uint8_t *toWrite;
2039
2040 toWrite = (const uint8_t *)buffer;
2041
2042 while (writeOffset < len) {
2043 ssize_t written;
2044 do {
2045 written = write (fd, toWrite + writeOffset,
2046 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05302047 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002048
2049 if (written >= 0) {
2050 writeOffset += written;
2051 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08002052 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002053 close(fd);
2054 return -1;
2055 }
2056 }
2057
2058 return 0;
2059}
2060
2061static int
Etan Cohend3652192014-06-20 08:28:44 -07002062sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2063 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002064 int ret;
2065 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07002066 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002067
Etan Cohend3652192014-06-20 08:28:44 -07002068 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
2069
2070#if (SIM_COUNT >= 2)
2071 if (socket_id == RIL_SOCKET_2) {
2072 fd = s_ril_param_socket2.fdCommand;
2073 writeMutexHook = &s_writeMutex_socket2;
2074 }
2075#if (SIM_COUNT >= 3)
2076 else if (socket_id == RIL_SOCKET_3) {
2077 fd = s_ril_param_socket3.fdCommand;
2078 writeMutexHook = &s_writeMutex_socket3;
2079 }
2080#endif
2081#if (SIM_COUNT >= 4)
2082 else if (socket_id == RIL_SOCKET_4) {
2083 fd = s_ril_param_socket4.fdCommand;
2084 writeMutexHook = &s_writeMutex_socket4;
2085 }
2086#endif
2087#endif
2088 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002089 return -1;
2090 }
2091
2092 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002093 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002094 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2095
2096 return -1;
2097 }
Wink Saville7f856802009-06-09 10:23:37 -07002098
Etan Cohend3652192014-06-20 08:28:44 -07002099 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002100
2101 header = htonl(dataSize);
2102
2103 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2104
2105 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002106 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002107 return ret;
2108 }
2109
Kennyee1fadc2009-08-13 00:45:53 +08002110 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002111
2112 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07002113 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002114 return ret;
2115 }
2116
Etan Cohend3652192014-06-20 08:28:44 -07002117 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002118
2119 return 0;
2120}
2121
2122static int
Etan Cohend3652192014-06-20 08:28:44 -07002123sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002124 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07002125 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126}
2127
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07002128/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07002129
2130static int
Wink Savillef4c4d362009-04-02 01:37:03 -07002131responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132 int numInts;
2133