blob: a251b4d4aacf5d50131550d795f0c5708a7acf8c [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);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800278static int responseInts(Parcel &p, void *response, size_t responselen);
279static int responseStrings(Parcel &p, void *response, size_t responselen);
280static int responseString(Parcel &p, void *response, size_t responselen);
281static int responseVoid(Parcel &p, void *response, size_t responselen);
282static int responseCallList(Parcel &p, void *response, size_t responselen);
283static int responseSMS(Parcel &p, void *response, size_t responselen);
284static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
285static int responseCallForwards(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700286static int responseDataCallList(Parcel &p, void *response, size_t responselen);
Wink Saville43808972011-01-13 17:39:51 -0800287static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800288static int responseRaw(Parcel &p, void *response, size_t responselen);
289static int responseSsn(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700290static int responseSimStatus(Parcel &p, void *response, size_t responselen);
Wink Savillea592eeb2009-05-22 13:26:36 -0700291static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
292static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
Wink Savillef4c4d362009-04-02 01:37:03 -0700293static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800294static int responseCellList(Parcel &p, void *response, size_t responselen);
Wink Saville3d54e742009-05-18 18:00:44 -0700295static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
296static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
297static int responseCallRing(Parcel &p, void *response, size_t responselen);
298static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
299static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
Alex Yakavenka45e740e2012-01-31 11:48:27 -0800300static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
Wink Saville8a9e0212013-04-09 12:11:38 -0700301static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Etan Cohend3652192014-06-20 08:28:44 -0700302static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800303
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800304static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
305static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
306static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
307
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800308#ifdef RIL_SHLIB
Etan Cohend3652192014-06-20 08:28:44 -0700309#if defined(ANDROID_MULTI_SIM)
310extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
311 size_t datalen, RIL_SOCKET_ID socket_id);
312#else
Wink Saville7f856802009-06-09 10:23:37 -0700313extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800314 size_t datalen);
315#endif
Etan Cohend3652192014-06-20 08:28:44 -0700316#endif
317
318#if defined(ANDROID_MULTI_SIM)
319#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
320#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
321#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
322#else
323#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
324#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
325#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
326#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800327
Wink Saville7f856802009-06-09 10:23:37 -0700328static UserCallbackInfo * internalRequestTimedCallback
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -0700329 (RIL_TimedCallback callback, void *param,
330 const struct timeval *relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800331
332/** Index == requestNumber */
333static CommandInfo s_commands[] = {
334#include "ril_commands.h"
335};
336
337static UnsolResponseInfo s_unsolResponses[] = {
338#include "ril_unsol_commands.h"
339};
340
Naveen Kalla2bc78d62011-12-07 16:22:53 -0800341/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
342 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
343 radio state message and store it. Every time there is a change in Radio State
344 check to see if voice radio tech changes and notify telephony
345 */
346int voiceRadioTech = -1;
347
348/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
349 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
350 source from radio state and store it. Every time there is a change in Radio State
351 check to see if subscription source changed and notify telephony
352 */
353int cdmaSubscriptionSource = -1;
354
355/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
356 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
357 check to see if SIM/RUIM status changed and notify telephony
358 */
359int simRuimStatus = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800360
Etan Cohend3652192014-06-20 08:28:44 -0700361static char * RIL_getRilSocketName() {
362 return rild;
363}
364
365extern "C"
366void RIL_setRilSocketName(char * s) {
367 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
368}
369
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800370static char *
Wink Savillef4c4d362009-04-02 01:37:03 -0700371strdupReadString(Parcel &p) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800372 size_t stringlen;
373 const char16_t *s16;
Wink Saville7f856802009-06-09 10:23:37 -0700374
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800375 s16 = p.readString16Inplace(&stringlen);
Wink Saville7f856802009-06-09 10:23:37 -0700376
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800377 return strndup16to8(s16, stringlen);
378}
379
Wink Savillef4c4d362009-04-02 01:37:03 -0700380static void writeStringToParcel(Parcel &p, const char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800381 char16_t *s16;
382 size_t s16_len;
383 s16 = strdup8to16(s, &s16_len);
384 p.writeString16(s16, s16_len);
385 free(s16);
386}
387
388
389static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700390memsetString (char *s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800391 if (s != NULL) {
392 memset (s, 0, strlen(s));
393 }
394}
395
396void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
397 const size_t* objects, size_t objectsSize,
Wink Savillef4c4d362009-04-02 01:37:03 -0700398 void* cookie) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800399 // do nothing -- the data reference lives longer than the Parcel object
400}
401
Wink Saville7f856802009-06-09 10:23:37 -0700402/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800403 * To be called from dispatch thread
404 * Issue a single local request, ensuring that the response
Wink Saville7f856802009-06-09 10:23:37 -0700405 * is not sent back up to the command process
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800406 */
407static void
Etan Cohend3652192014-06-20 08:28:44 -0700408issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800409 RequestInfo *pRI;
410 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700411 /* Hook for current context */
412 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
413 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
414 /* pendingRequestsHook refer to &s_pendingRequests */
415 RequestInfo** pendingRequestsHook = &s_pendingRequests;
416
417#if (SIM_COUNT == 2)
418 if (socket_id == RIL_SOCKET_2) {
419 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
420 pendingRequestsHook = &s_pendingRequests_socket2;
421 }
422#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800423
424 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
425
426 pRI->local = 1;
427 pRI->token = 0xffffffff; // token is not used in this context
428 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700429 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800430
Etan Cohend3652192014-06-20 08:28:44 -0700431 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800432 assert (ret == 0);
433
Etan Cohend3652192014-06-20 08:28:44 -0700434 pRI->p_next = *pendingRequestsHook;
435 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800436
Etan Cohend3652192014-06-20 08:28:44 -0700437 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800438 assert (ret == 0);
439
Wink Saville8eb2a122012-11-19 16:05:13 -0800440 RLOGD("C[locl]> %s", requestToString(request));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800441
Etan Cohend3652192014-06-20 08:28:44 -0700442 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800443}
444
445
446
447static int
Etan Cohend3652192014-06-20 08:28:44 -0700448processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800449 Parcel p;
450 status_t status;
451 int32_t request;
452 int32_t token;
453 RequestInfo *pRI;
454 int ret;
Etan Cohend3652192014-06-20 08:28:44 -0700455 /* Hook for current context */
456 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
457 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
458 /* pendingRequestsHook refer to &s_pendingRequests */
459 RequestInfo** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800460
461 p.setData((uint8_t *) buffer, buflen);
462
463 // status checked at end
464 status = p.readInt32(&request);
465 status = p.readInt32 (&token);
466
Etan Cohend3652192014-06-20 08:28:44 -0700467 RLOGD("SOCKET %s REQUEST: %s length:%d", rilSocketIdToString(socket_id), requestToString(request), buflen);
468
469#if (SIM_COUNT >= 2)
470 if (socket_id == RIL_SOCKET_2) {
471 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
472 pendingRequestsHook = &s_pendingRequests_socket2;
473 }
474#if (SIM_COUNT >= 3)
475 else if (socket_id == RIL_SOCKET_3) {
476 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
477 pendingRequestsHook = &s_pendingRequests_socket3;
478 }
479#endif
480#if (SIM_COUNT >= 4)
481 else if (socket_id == RIL_SOCKET_4) {
482 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
483 pendingRequestsHook = &s_pendingRequests_socket4;
484 }
485#endif
486#endif
487
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800488 if (status != NO_ERROR) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800489 RLOGE("invalid request block");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800490 return 0;
491 }
492
493 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
Etan Cohend3652192014-06-20 08:28:44 -0700494 Parcel pErr;
Wink Saville8eb2a122012-11-19 16:05:13 -0800495 RLOGE("unsupported request code %d token %d", request, token);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800496 // FIXME this should perhaps return a response
Etan Cohend3652192014-06-20 08:28:44 -0700497 pErr.writeInt32 (RESPONSE_SOLICITED);
498 pErr.writeInt32 (token);
499 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
500
501 sendResponse(pErr, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800502 return 0;
503 }
504
505
506 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
507
508 pRI->token = token;
509 pRI->pCI = &(s_commands[request]);
Etan Cohend3652192014-06-20 08:28:44 -0700510 pRI->socket_id = socket_id;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800511
Etan Cohend3652192014-06-20 08:28:44 -0700512 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800513 assert (ret == 0);
514
Etan Cohend3652192014-06-20 08:28:44 -0700515 pRI->p_next = *pendingRequestsHook;
516 *pendingRequestsHook = pRI;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800517
Etan Cohend3652192014-06-20 08:28:44 -0700518 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800519 assert (ret == 0);
520
521/* sLastDispatchedToken = token; */
522
Wink Saville7f856802009-06-09 10:23:37 -0700523 pRI->pCI->dispatchFunction(p, pRI);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800524
525 return 0;
526}
527
528static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700529invalidCommandBlock (RequestInfo *pRI) {
Wink Saville8eb2a122012-11-19 16:05:13 -0800530 RLOGE("invalid command block for token %d request %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800531 pRI->token, requestToString(pRI->pCI->requestNumber));
532}
533
534/** Callee expects NULL */
Wink Saville7f856802009-06-09 10:23:37 -0700535static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700536dispatchVoid (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800537 clearPrintBuf;
538 printRequest(pRI->token, pRI->pCI->requestNumber);
Etan Cohend3652192014-06-20 08:28:44 -0700539 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800540}
541
542/** Callee expects const char * */
543static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700544dispatchString (Parcel& p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800545 status_t status;
546 size_t datalen;
547 size_t stringlen;
548 char *string8 = NULL;
549
550 string8 = strdupReadString(p);
551
552 startRequest;
553 appendPrintBuf("%s%s", printBuf, string8);
554 closeRequest;
555 printRequest(pRI->token, pRI->pCI->requestNumber);
556
Etan Cohend3652192014-06-20 08:28:44 -0700557 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
558 sizeof(char *), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800559
560#ifdef MEMSET_FREED
561 memsetString(string8);
562#endif
563
564 free(string8);
565 return;
566invalid:
567 invalidCommandBlock(pRI);
568 return;
569}
570
571/** Callee expects const char ** */
572static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700573dispatchStrings (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800574 int32_t countStrings;
575 status_t status;
576 size_t datalen;
577 char **pStrings;
578
579 status = p.readInt32 (&countStrings);
580
581 if (status != NO_ERROR) {
582 goto invalid;
583 }
584
585 startRequest;
586 if (countStrings == 0) {
587 // just some non-null pointer
588 pStrings = (char **)alloca(sizeof(char *));
589 datalen = 0;
590 } else if (((int)countStrings) == -1) {
591 pStrings = NULL;
592 datalen = 0;
593 } else {
594 datalen = sizeof(char *) * countStrings;
Wink Saville7f856802009-06-09 10:23:37 -0700595
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800596 pStrings = (char **)alloca(datalen);
597
598 for (int i = 0 ; i < countStrings ; i++) {
599 pStrings[i] = strdupReadString(p);
600 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
601 }
602 }
603 removeLastChar;
604 closeRequest;
605 printRequest(pRI->token, pRI->pCI->requestNumber);
606
Etan Cohend3652192014-06-20 08:28:44 -0700607 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800608
609 if (pStrings != NULL) {
610 for (int i = 0 ; i < countStrings ; i++) {
611#ifdef MEMSET_FREED
612 memsetString (pStrings[i]);
613#endif
614 free(pStrings[i]);
615 }
616
617#ifdef MEMSET_FREED
618 memset(pStrings, 0, datalen);
619#endif
620 }
Wink Saville7f856802009-06-09 10:23:37 -0700621
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800622 return;
623invalid:
624 invalidCommandBlock(pRI);
625 return;
626}
627
628/** Callee expects const int * */
629static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700630dispatchInts (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800631 int32_t count;
632 status_t status;
633 size_t datalen;
634 int *pInts;
635
636 status = p.readInt32 (&count);
637
638 if (status != NO_ERROR || count == 0) {
639 goto invalid;
640 }
641
642 datalen = sizeof(int) * count;
643 pInts = (int *)alloca(datalen);
644
645 startRequest;
646 for (int i = 0 ; i < count ; i++) {
647 int32_t t;
648
649 status = p.readInt32(&t);
650 pInts[i] = (int)t;
651 appendPrintBuf("%s%d,", printBuf, t);
652
653 if (status != NO_ERROR) {
654 goto invalid;
655 }
656 }
657 removeLastChar;
658 closeRequest;
659 printRequest(pRI->token, pRI->pCI->requestNumber);
660
Etan Cohend3652192014-06-20 08:28:44 -0700661 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
662 datalen, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800663
664#ifdef MEMSET_FREED
665 memset(pInts, 0, datalen);
666#endif
667
668 return;
669invalid:
670 invalidCommandBlock(pRI);
671 return;
672}
673
674
Wink Saville7f856802009-06-09 10:23:37 -0700675/**
676 * Callee expects const RIL_SMS_WriteArgs *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800677 * Payload is:
678 * int32_t status
679 * String pdu
680 */
681static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700682dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800683 RIL_SMS_WriteArgs args;
684 int32_t t;
685 status_t status;
686
687 memset (&args, 0, sizeof(args));
688
689 status = p.readInt32(&t);
690 args.status = (int)t;
691
692 args.pdu = strdupReadString(p);
693
694 if (status != NO_ERROR || args.pdu == NULL) {
695 goto invalid;
696 }
697
698 args.smsc = strdupReadString(p);
699
700 startRequest;
701 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
702 (char*)args.pdu, (char*)args.smsc);
703 closeRequest;
704 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700705
Etan Cohend3652192014-06-20 08:28:44 -0700706 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800707
708#ifdef MEMSET_FREED
709 memsetString (args.pdu);
710#endif
711
712 free (args.pdu);
Wink Saville7f856802009-06-09 10:23:37 -0700713
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800714#ifdef MEMSET_FREED
715 memset(&args, 0, sizeof(args));
716#endif
717
718 return;
719invalid:
720 invalidCommandBlock(pRI);
721 return;
722}
723
Wink Saville7f856802009-06-09 10:23:37 -0700724/**
725 * Callee expects const RIL_Dial *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800726 * Payload is:
727 * String address
728 * int32_t clir
729 */
730static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700731dispatchDial (Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800732 RIL_Dial dial;
Wink Saville74fa3882009-12-22 15:35:41 -0800733 RIL_UUS_Info uusInfo;
Wink Saville7bce0822010-01-08 15:20:12 -0800734 int32_t sizeOfDial;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800735 int32_t t;
Wink Saville74fa3882009-12-22 15:35:41 -0800736 int32_t uusPresent;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800737 status_t status;
738
739 memset (&dial, 0, sizeof(dial));
740
741 dial.address = strdupReadString(p);
742
743 status = p.readInt32(&t);
744 dial.clir = (int)t;
745
746 if (status != NO_ERROR || dial.address == NULL) {
747 goto invalid;
748 }
749
Wink Saville3a4840b2010-04-07 13:29:58 -0700750 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -0800751 uusPresent = 0;
Wink Saville7bce0822010-01-08 15:20:12 -0800752 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
Wink Saville74fa3882009-12-22 15:35:41 -0800753 } else {
754 status = p.readInt32(&uusPresent);
755
756 if (status != NO_ERROR) {
757 goto invalid;
758 }
759
760 if (uusPresent == 0) {
761 dial.uusInfo = NULL;
762 } else {
763 int32_t len;
764
765 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
766
767 status = p.readInt32(&t);
768 uusInfo.uusType = (RIL_UUS_Type) t;
769
770 status = p.readInt32(&t);
771 uusInfo.uusDcs = (RIL_UUS_DCS) t;
772
773 status = p.readInt32(&len);
774 if (status != NO_ERROR) {
775 goto invalid;
776 }
777
778 // The java code writes -1 for null arrays
779 if (((int) len) == -1) {
780 uusInfo.uusData = NULL;
781 len = 0;
782 } else {
783 uusInfo.uusData = (char*) p.readInplace(len);
784 }
785
786 uusInfo.uusLength = len;
787 dial.uusInfo = &uusInfo;
788 }
Wink Saville7bce0822010-01-08 15:20:12 -0800789 sizeOfDial = sizeof(dial);
Wink Saville74fa3882009-12-22 15:35:41 -0800790 }
791
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800792 startRequest;
793 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
Wink Saville74fa3882009-12-22 15:35:41 -0800794 if (uusPresent) {
795 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
796 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
797 dial.uusInfo->uusLength);
798 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800799 closeRequest;
800 printRequest(pRI->token, pRI->pCI->requestNumber);
801
Etan Cohend3652192014-06-20 08:28:44 -0700802 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800803
804#ifdef MEMSET_FREED
805 memsetString (dial.address);
806#endif
807
808 free (dial.address);
Wink Saville7f856802009-06-09 10:23:37 -0700809
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800810#ifdef MEMSET_FREED
Wink Saville74fa3882009-12-22 15:35:41 -0800811 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800812 memset(&dial, 0, sizeof(dial));
813#endif
814
815 return;
816invalid:
817 invalidCommandBlock(pRI);
818 return;
819}
820
Wink Saville7f856802009-06-09 10:23:37 -0700821/**
822 * Callee expects const RIL_SIM_IO *
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800823 * Payload is:
824 * int32_t command
825 * int32_t fileid
826 * String path
827 * int32_t p1, p2, p3
Wink Saville7f856802009-06-09 10:23:37 -0700828 * String data
829 * String pin2
Wink Savillec0114b32011-02-18 10:14:07 -0800830 * String aidPtr
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800831 */
832static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700833dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
Wink Savillec0114b32011-02-18 10:14:07 -0800834 union RIL_SIM_IO {
835 RIL_SIM_IO_v6 v6;
836 RIL_SIM_IO_v5 v5;
837 } simIO;
838
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800839 int32_t t;
Wink Savillec0114b32011-02-18 10:14:07 -0800840 int size;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800841 status_t status;
842
843 memset (&simIO, 0, sizeof(simIO));
844
Wink Saville7f856802009-06-09 10:23:37 -0700845 // note we only check status at the end
846
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800847 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800848 simIO.v6.command = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800849
850 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800851 simIO.v6.fileid = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800852
Wink Savillec0114b32011-02-18 10:14:07 -0800853 simIO.v6.path = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800854
855 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800856 simIO.v6.p1 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800857
858 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800859 simIO.v6.p2 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800860
861 status = p.readInt32(&t);
Wink Savillec0114b32011-02-18 10:14:07 -0800862 simIO.v6.p3 = (int)t;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800863
Wink Savillec0114b32011-02-18 10:14:07 -0800864 simIO.v6.data = strdupReadString(p);
865 simIO.v6.pin2 = strdupReadString(p);
866 simIO.v6.aidPtr = strdupReadString(p);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800867
868 startRequest;
Wink Savillec0114b32011-02-18 10:14:07 -0800869 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
870 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
871 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
872 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800873 closeRequest;
874 printRequest(pRI->token, pRI->pCI->requestNumber);
Wink Saville7f856802009-06-09 10:23:37 -0700875
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800876 if (status != NO_ERROR) {
877 goto invalid;
878 }
879
Wink Savillec0114b32011-02-18 10:14:07 -0800880 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Etan Cohend3652192014-06-20 08:28:44 -0700881 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800882
883#ifdef MEMSET_FREED
Wink Savillec0114b32011-02-18 10:14:07 -0800884 memsetString (simIO.v6.path);
885 memsetString (simIO.v6.data);
886 memsetString (simIO.v6.pin2);
887 memsetString (simIO.v6.aidPtr);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800888#endif
889
Wink Savillec0114b32011-02-18 10:14:07 -0800890 free (simIO.v6.path);
891 free (simIO.v6.data);
892 free (simIO.v6.pin2);
893 free (simIO.v6.aidPtr);
Wink Saville7f856802009-06-09 10:23:37 -0700894
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800895#ifdef MEMSET_FREED
896 memset(&simIO, 0, sizeof(simIO));
897#endif
898
899 return;
900invalid:
901 invalidCommandBlock(pRI);
902 return;
903}
904
905/**
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800906 * Callee expects const RIL_SIM_APDU *
907 * Payload is:
908 * int32_t sessionid
909 * int32_t cla
910 * int32_t instruction
911 * int32_t p1, p2, p3
912 * String data
913 */
914static void
915dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
916 int32_t t;
917 status_t status;
918 RIL_SIM_APDU apdu;
919
920 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
921
922 // Note we only check status at the end. Any single failure leads to
923 // subsequent reads filing.
924 status = p.readInt32(&t);
925 apdu.sessionid = (int)t;
926
927 status = p.readInt32(&t);
928 apdu.cla = (int)t;
929
930 status = p.readInt32(&t);
931 apdu.instruction = (int)t;
932
933 status = p.readInt32(&t);
934 apdu.p1 = (int)t;
935
936 status = p.readInt32(&t);
937 apdu.p2 = (int)t;
938
939 status = p.readInt32(&t);
940 apdu.p3 = (int)t;
941
942 apdu.data = strdupReadString(p);
943
944 startRequest;
945 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
946 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
947 apdu.p3, (char*)apdu.data);
948 closeRequest;
949 printRequest(pRI->token, pRI->pCI->requestNumber);
950
951 if (status != NO_ERROR) {
952 goto invalid;
953 }
954
Etan Cohend3652192014-06-20 08:28:44 -0700955 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
Shishir Agrawal2458d8d2013-11-27 14:53:05 -0800956
957#ifdef MEMSET_FREED
958 memsetString(apdu.data);
959#endif
960 free(apdu.data);
961
962#ifdef MEMSET_FREED
963 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
964#endif
965
966 return;
967invalid:
968 invalidCommandBlock(pRI);
969 return;
970}
971
972
973/**
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800974 * Callee expects const RIL_CallForwardInfo *
975 * Payload is:
976 * int32_t status/action
977 * int32_t reason
978 * int32_t serviceCode
979 * int32_t toa
980 * String number (0 length -> null)
981 * int32_t timeSeconds
982 */
Wink Saville7f856802009-06-09 10:23:37 -0700983static void
Wink Savillef4c4d362009-04-02 01:37:03 -0700984dispatchCallForward(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800985 RIL_CallForwardInfo cff;
986 int32_t t;
987 status_t status;
988
989 memset (&cff, 0, sizeof(cff));
990
Wink Saville7f856802009-06-09 10:23:37 -0700991 // note we only check status at the end
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800992
993 status = p.readInt32(&t);
994 cff.status = (int)t;
Wink Saville7f856802009-06-09 10:23:37 -0700995
The Android Open Source Project00f06fc2009-03-03 19:32:15 -0800996 status = p.readInt32(&t);
997 cff.reason = (int)t;
998
999 status = p.readInt32(&t);
1000 cff.serviceClass = (int)t;
1001
1002 status = p.readInt32(&t);
1003 cff.toa = (int)t;
1004
1005 cff.number = strdupReadString(p);
1006
1007 status = p.readInt32(&t);
1008 cff.timeSeconds = (int)t;
1009
1010 if (status != NO_ERROR) {
1011 goto invalid;
1012 }
1013
1014 // special case: number 0-length fields is null
1015
1016 if (cff.number != NULL && strlen (cff.number) == 0) {
1017 cff.number = NULL;
1018 }
1019
1020 startRequest;
1021 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1022 cff.status, cff.reason, cff.serviceClass, cff.toa,
1023 (char*)cff.number, cff.timeSeconds);
1024 closeRequest;
1025 printRequest(pRI->token, pRI->pCI->requestNumber);
1026
Etan Cohend3652192014-06-20 08:28:44 -07001027 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001028
1029#ifdef MEMSET_FREED
1030 memsetString(cff.number);
1031#endif
1032
1033 free (cff.number);
1034
1035#ifdef MEMSET_FREED
1036 memset(&cff, 0, sizeof(cff));
1037#endif
1038
1039 return;
1040invalid:
1041 invalidCommandBlock(pRI);
1042 return;
1043}
1044
1045
Wink Saville7f856802009-06-09 10:23:37 -07001046static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001047dispatchRaw(Parcel &p, RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001048 int32_t len;
1049 status_t status;
1050 const void *data;
1051
1052 status = p.readInt32(&len);
1053
1054 if (status != NO_ERROR) {
1055 goto invalid;
1056 }
1057
1058 // The java code writes -1 for null arrays
1059 if (((int)len) == -1) {
1060 data = NULL;
1061 len = 0;
Wink Saville7f856802009-06-09 10:23:37 -07001062 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001063
1064 data = p.readInplace(len);
1065
1066 startRequest;
1067 appendPrintBuf("%sraw_size=%d", printBuf, len);
1068 closeRequest;
1069 printRequest(pRI->token, pRI->pCI->requestNumber);
1070
Etan Cohend3652192014-06-20 08:28:44 -07001071 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001072
1073 return;
1074invalid:
1075 invalidCommandBlock(pRI);
1076 return;
1077}
1078
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001079static status_t
1080constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Wink Savillef4c4d362009-04-02 01:37:03 -07001081 int32_t t;
1082 uint8_t ut;
1083 status_t status;
1084 int32_t digitCount;
1085 int digitLimit;
Wink Saville7f856802009-06-09 10:23:37 -07001086
Wink Savillef4c4d362009-04-02 01:37:03 -07001087 memset(&rcsm, 0, sizeof(rcsm));
1088
1089 status = p.readInt32(&t);
1090 rcsm.uTeleserviceID = (int) t;
1091
1092 status = p.read(&ut,sizeof(ut));
1093 rcsm.bIsServicePresent = (uint8_t) ut;
1094
1095 status = p.readInt32(&t);
1096 rcsm.uServicecategory = (int) t;
1097
1098 status = p.readInt32(&t);
1099 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1100
1101 status = p.readInt32(&t);
1102 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1103
1104 status = p.readInt32(&t);
1105 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1106
1107 status = p.readInt32(&t);
1108 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1109
1110 status = p.read(&ut,sizeof(ut));
1111 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1112
1113 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1114 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1115 status = p.read(&ut,sizeof(ut));
1116 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1117 }
1118
Wink Saville7f856802009-06-09 10:23:37 -07001119 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001120 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1121
Wink Saville7f856802009-06-09 10:23:37 -07001122 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001123 rcsm.sSubAddress.odd = (uint8_t) ut;
1124
1125 status = p.read(&ut,sizeof(ut));
1126 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1127
1128 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001129 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1130 status = p.read(&ut,sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001131 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1132 }
1133
Wink Saville7f856802009-06-09 10:23:37 -07001134 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001135 rcsm.uBearerDataLen = (int) t;
1136
1137 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
Wink Saville7f856802009-06-09 10:23:37 -07001138 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1139 status = p.read(&ut, sizeof(ut));
Wink Savillef4c4d362009-04-02 01:37:03 -07001140 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1141 }
1142
1143 if (status != NO_ERROR) {
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001144 return status;
Wink Savillef4c4d362009-04-02 01:37:03 -07001145 }
1146
1147 startRequest;
1148 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07001149 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001150 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
Wink Saville1b5fd232009-04-22 14:50:00 -07001151 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001152 closeRequest;
Wink Saville7f856802009-06-09 10:23:37 -07001153
Wink Savillef4c4d362009-04-02 01:37:03 -07001154 printRequest(pRI->token, pRI->pCI->requestNumber);
1155
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001156 return status;
1157}
1158
1159static void
1160dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1161 RIL_CDMA_SMS_Message rcsm;
1162
1163 ALOGD("dispatchCdmaSms");
1164 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1165 goto invalid;
1166 }
1167
Etan Cohend3652192014-06-20 08:28:44 -07001168 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001169
1170#ifdef MEMSET_FREED
1171 memset(&rcsm, 0, sizeof(rcsm));
1172#endif
1173
1174 return;
1175
1176invalid:
1177 invalidCommandBlock(pRI);
1178 return;
1179}
1180
Wink Saville7f856802009-06-09 10:23:37 -07001181static void
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001182dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1183 RIL_IMS_SMS_Message rism;
1184 RIL_CDMA_SMS_Message rcsm;
1185
1186 ALOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
1187
1188 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1189 goto invalid;
1190 }
1191 memset(&rism, 0, sizeof(rism));
1192 rism.tech = RADIO_TECH_3GPP2;
1193 rism.retry = retry;
1194 rism.messageRef = messageRef;
1195 rism.message.cdmaMessage = &rcsm;
1196
Etan Cohend3652192014-06-20 08:28:44 -07001197 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001198 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001199 +sizeof(rcsm),pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001200
1201#ifdef MEMSET_FREED
1202 memset(&rcsm, 0, sizeof(rcsm));
1203 memset(&rism, 0, sizeof(rism));
1204#endif
1205
1206 return;
1207
1208invalid:
1209 invalidCommandBlock(pRI);
1210 return;
1211}
1212
1213static void
1214dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1215 RIL_IMS_SMS_Message rism;
1216 int32_t countStrings;
1217 status_t status;
1218 size_t datalen;
1219 char **pStrings;
1220 ALOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
1221
1222 status = p.readInt32 (&countStrings);
1223
1224 if (status != NO_ERROR) {
1225 goto invalid;
1226 }
1227
1228 memset(&rism, 0, sizeof(rism));
1229 rism.tech = RADIO_TECH_3GPP;
1230 rism.retry = retry;
1231 rism.messageRef = messageRef;
1232
1233 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001234 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1235 (int)rism.tech, (int)rism.retry, rism.messageRef);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001236 if (countStrings == 0) {
1237 // just some non-null pointer
1238 pStrings = (char **)alloca(sizeof(char *));
1239 datalen = 0;
1240 } else if (((int)countStrings) == -1) {
1241 pStrings = NULL;
1242 datalen = 0;
1243 } else {
1244 datalen = sizeof(char *) * countStrings;
1245
1246 pStrings = (char **)alloca(datalen);
1247
1248 for (int i = 0 ; i < countStrings ; i++) {
1249 pStrings[i] = strdupReadString(p);
1250 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1251 }
1252 }
1253 removeLastChar;
1254 closeRequest;
1255 printRequest(pRI->token, pRI->pCI->requestNumber);
1256
1257 rism.message.gsmMessage = pStrings;
Etan Cohend3652192014-06-20 08:28:44 -07001258 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001259 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Etan Cohend3652192014-06-20 08:28:44 -07001260 +datalen, pRI, pRI->socket_id);
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07001261
1262 if (pStrings != NULL) {
1263 for (int i = 0 ; i < countStrings ; i++) {
1264#ifdef MEMSET_FREED
1265 memsetString (pStrings[i]);
1266#endif
1267 free(pStrings[i]);
1268 }
1269
1270#ifdef MEMSET_FREED
1271 memset(pStrings, 0, datalen);
1272#endif
1273 }
1274
1275#ifdef MEMSET_FREED
1276 memset(&rism, 0, sizeof(rism));
1277#endif
1278 return;
1279invalid:
1280 ALOGE("dispatchImsGsmSms invalid block");
1281 invalidCommandBlock(pRI);
1282 return;
1283}
1284
1285static void
1286dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1287 int32_t t;
1288 status_t status = p.readInt32(&t);
1289 RIL_RadioTechnologyFamily format;
1290 uint8_t retry;
1291 int32_t messageRef;
1292
1293 ALOGD("dispatchImsSms");
1294 if (status != NO_ERROR) {
1295 goto invalid;
1296 }
1297 format = (RIL_RadioTechnologyFamily) t;
1298
1299 // read retry field
1300 status = p.read(&retry,sizeof(retry));
1301 if (status != NO_ERROR) {
1302 goto invalid;
1303 }
1304 // read messageRef field
1305 status = p.read(&messageRef,sizeof(messageRef));
1306 if (status != NO_ERROR) {
1307 goto invalid;
1308 }
1309
1310 if (RADIO_TECH_3GPP == format) {
1311 dispatchImsGsmSms(p, pRI, retry, messageRef);
1312 } else if (RADIO_TECH_3GPP2 == format) {
1313 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1314 } else {
1315 ALOGE("requestImsSendSMS invalid format value =%d", format);
1316 }
1317
1318 return;
1319
1320invalid:
1321 invalidCommandBlock(pRI);
1322 return;
1323}
1324
1325static void
Wink Savillef4c4d362009-04-02 01:37:03 -07001326dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1327 RIL_CDMA_SMS_Ack rcsa;
1328 int32_t t;
1329 status_t status;
1330 int32_t digitCount;
1331
1332 memset(&rcsa, 0, sizeof(rcsa));
1333
1334 status = p.readInt32(&t);
1335 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1336
1337 status = p.readInt32(&t);
1338 rcsa.uSMSCauseCode = (int) t;
1339
1340 if (status != NO_ERROR) {
1341 goto invalid;
1342 }
1343
1344 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001345 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1346 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
Wink Savillef4c4d362009-04-02 01:37:03 -07001347 closeRequest;
1348
1349 printRequest(pRI->token, pRI->pCI->requestNumber);
1350
Etan Cohend3652192014-06-20 08:28:44 -07001351 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001352
1353#ifdef MEMSET_FREED
1354 memset(&rcsa, 0, sizeof(rcsa));
1355#endif
1356
1357 return;
1358
1359invalid:
1360 invalidCommandBlock(pRI);
1361 return;
1362}
1363
Wink Savillea592eeb2009-05-22 13:26:36 -07001364static void
1365dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1366 int32_t t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001367 status_t status;
Wink Savillea592eeb2009-05-22 13:26:36 -07001368 int32_t num;
Wink Savillef4c4d362009-04-02 01:37:03 -07001369
Wink Savillea592eeb2009-05-22 13:26:36 -07001370 status = p.readInt32(&num);
Wink Savillef4c4d362009-04-02 01:37:03 -07001371 if (status != NO_ERROR) {
1372 goto invalid;
1373 }
1374
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001375 {
1376 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1377 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001378
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001379 startRequest;
1380 for (int i = 0 ; i < num ; i++ ) {
1381 gsmBciPtrs[i] = &gsmBci[i];
Wink Savillef4c4d362009-04-02 01:37:03 -07001382
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001383 status = p.readInt32(&t);
1384 gsmBci[i].fromServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001385
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001386 status = p.readInt32(&t);
1387 gsmBci[i].toServiceId = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001388
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001389 status = p.readInt32(&t);
1390 gsmBci[i].fromCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001391
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001392 status = p.readInt32(&t);
1393 gsmBci[i].toCodeScheme = (int) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001394
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001395 status = p.readInt32(&t);
1396 gsmBci[i].selected = (uint8_t) t;
Wink Savillef4c4d362009-04-02 01:37:03 -07001397
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001398 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1399 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1400 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1401 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1402 gsmBci[i].selected);
1403 }
1404 closeRequest;
Wink Savillef4c4d362009-04-02 01:37:03 -07001405
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001406 if (status != NO_ERROR) {
1407 goto invalid;
1408 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001409
Etan Cohend3652192014-06-20 08:28:44 -07001410 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001411 gsmBciPtrs,
1412 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001413 pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001414
1415#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001416 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1417 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Wink Savillef4c4d362009-04-02 01:37:03 -07001418#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001419 }
Wink Savillef4c4d362009-04-02 01:37:03 -07001420
1421 return;
1422
1423invalid:
1424 invalidCommandBlock(pRI);
1425 return;
Wink Savillea592eeb2009-05-22 13:26:36 -07001426}
Wink Savillef4c4d362009-04-02 01:37:03 -07001427
Wink Savillea592eeb2009-05-22 13:26:36 -07001428static void
1429dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1430 int32_t t;
1431 status_t status;
1432 int32_t num;
1433
1434 status = p.readInt32(&num);
1435 if (status != NO_ERROR) {
1436 goto invalid;
1437 }
1438
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001439 {
1440 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1441 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Wink Savillea592eeb2009-05-22 13:26:36 -07001442
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001443 startRequest;
1444 for (int i = 0 ; i < num ; i++ ) {
1445 cdmaBciPtrs[i] = &cdmaBci[i];
Wink Savillea592eeb2009-05-22 13:26:36 -07001446
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001447 status = p.readInt32(&t);
1448 cdmaBci[i].service_category = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001449
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001450 status = p.readInt32(&t);
1451 cdmaBci[i].language = (int) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001452
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001453 status = p.readInt32(&t);
1454 cdmaBci[i].selected = (uint8_t) t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001455
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001456 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1457 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1458 cdmaBci[i].language, cdmaBci[i].selected);
1459 }
1460 closeRequest;
Wink Savillea592eeb2009-05-22 13:26:36 -07001461
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001462 if (status != NO_ERROR) {
1463 goto invalid;
1464 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001465
Etan Cohend3652192014-06-20 08:28:44 -07001466 CALL_ONREQUEST(pRI->pCI->requestNumber,
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001467 cdmaBciPtrs,
1468 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Etan Cohend3652192014-06-20 08:28:44 -07001469 pRI, pRI->socket_id);
Wink Savillea592eeb2009-05-22 13:26:36 -07001470
1471#ifdef MEMSET_FREED
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001472 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1473 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Wink Savillea592eeb2009-05-22 13:26:36 -07001474#endif
Kevin Schoedel96dcdbc2012-05-25 17:00:17 -04001475 }
Wink Savillea592eeb2009-05-22 13:26:36 -07001476
1477 return;
1478
1479invalid:
1480 invalidCommandBlock(pRI);
1481 return;
Wink Savillef4c4d362009-04-02 01:37:03 -07001482}
1483
1484static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1485 RIL_CDMA_SMS_WriteArgs rcsw;
1486 int32_t t;
1487 uint32_t ut;
1488 uint8_t uct;
1489 status_t status;
1490 int32_t digitCount;
1491
1492 memset(&rcsw, 0, sizeof(rcsw));
1493
1494 status = p.readInt32(&t);
1495 rcsw.status = t;
Wink Savillea592eeb2009-05-22 13:26:36 -07001496
Wink Savillef4c4d362009-04-02 01:37:03 -07001497 status = p.readInt32(&t);
1498 rcsw.message.uTeleserviceID = (int) t;
1499
1500 status = p.read(&uct,sizeof(uct));
1501 rcsw.message.bIsServicePresent = (uint8_t) uct;
1502
1503 status = p.readInt32(&t);
1504 rcsw.message.uServicecategory = (int) t;
1505
1506 status = p.readInt32(&t);
1507 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1508
1509 status = p.readInt32(&t);
1510 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1511
1512 status = p.readInt32(&t);
1513 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1514
1515 status = p.readInt32(&t);
1516 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1517
1518 status = p.read(&uct,sizeof(uct));
1519 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1520
1521 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1522 status = p.read(&uct,sizeof(uct));
1523 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1524 }
1525
Wink Savillea592eeb2009-05-22 13:26:36 -07001526 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001527 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1528
Wink Savillea592eeb2009-05-22 13:26:36 -07001529 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001530 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1531
1532 status = p.read(&uct,sizeof(uct));
1533 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1534
1535 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001536 status = p.read(&uct,sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001537 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1538 }
1539
Wink Savillea592eeb2009-05-22 13:26:36 -07001540 status = p.readInt32(&t);
Wink Savillef4c4d362009-04-02 01:37:03 -07001541 rcsw.message.uBearerDataLen = (int) t;
1542
1543 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
Wink Savillea592eeb2009-05-22 13:26:36 -07001544 status = p.read(&uct, sizeof(uct));
Wink Savillef4c4d362009-04-02 01:37:03 -07001545 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1546 }
1547
1548 if (status != NO_ERROR) {
1549 goto invalid;
1550 }
1551
1552 startRequest;
Wink Saville1b5fd232009-04-22 14:50:00 -07001553 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1554 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1555 message.sAddress.number_mode=%d, \
1556 message.sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07001557 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
Wink Saville1b5fd232009-04-22 14:50:00 -07001558 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1559 rcsw.message.sAddress.number_mode,
1560 rcsw.message.sAddress.number_type);
Wink Savillef4c4d362009-04-02 01:37:03 -07001561 closeRequest;
1562
1563 printRequest(pRI->token, pRI->pCI->requestNumber);
1564
Etan Cohend3652192014-06-20 08:28:44 -07001565 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Wink Savillef4c4d362009-04-02 01:37:03 -07001566
1567#ifdef MEMSET_FREED
1568 memset(&rcsw, 0, sizeof(rcsw));
1569#endif
1570
1571 return;
1572
1573invalid:
1574 invalidCommandBlock(pRI);
1575 return;
1576
1577}
1578
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001579// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1580// Version 4 of the RIL interface adds a new PDP type parameter to support
1581// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1582// RIL, remove the parameter from the request.
1583static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
1584 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
1585 const int numParamsRilV3 = 6;
1586
1587 // The first bytes of the RIL parcel contain the request number and the
1588 // serial number - see processCommandBuffer(). Copy them over too.
1589 int pos = p.dataPosition();
1590
1591 int numParams = p.readInt32();
1592 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1593 Parcel p2;
1594 p2.appendFrom(&p, 0, pos);
1595 p2.writeInt32(numParamsRilV3);
1596 for(int i = 0; i < numParamsRilV3; i++) {
1597 p2.writeString16(p.readString16());
1598 }
1599 p2.setDataPosition(pos);
1600 dispatchStrings(p2, pRI);
1601 } else {
Lorenzo Colitti57ce1f22010-09-13 12:23:50 -07001602 p.setDataPosition(pos);
Lorenzo Colitti4f81dcf2010-09-01 19:38:57 -07001603 dispatchStrings(p, pRI);
1604 }
1605}
1606
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001607// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
1608// When all RILs handle this request, this function can be removed and
1609// the request can be sent directly to the RIL using dispatchVoid.
1610static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001611 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001612
1613 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1614 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1615 }
1616
1617 // RILs that support RADIO_STATE_ON should support this request.
1618 if (RADIO_STATE_ON == state) {
1619 dispatchVoid(p, pRI);
1620 return;
1621 }
1622
1623 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1624 // will not support this new request either and decode Voice Radio Technology
1625 // from Radio State
1626 voiceRadioTech = decodeVoiceRadioTechnology(state);
1627
1628 if (voiceRadioTech < 0)
1629 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1630 else
1631 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1632}
1633
1634// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1635// When all RILs handle this request, this function can be removed and
1636// the request can be sent directly to the RIL using dispatchVoid.
1637static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Etan Cohend3652192014-06-20 08:28:44 -07001638 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08001639
1640 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1641 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1642 }
1643
1644 // RILs that support RADIO_STATE_ON should support this request.
1645 if (RADIO_STATE_ON == state) {
1646 dispatchVoid(p, pRI);
1647 return;
1648 }
1649
1650 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1651 // will not support this new request either and decode CDMA Subscription Source
1652 // from Radio State
1653 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1654
1655 if (cdmaSubscriptionSource < 0)
1656 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1657 else
1658 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1659}
1660
Sungmin Choi75697532013-04-26 15:04:45 -07001661static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1662{
1663 RIL_InitialAttachApn pf;
1664 int32_t t;
1665 status_t status;
1666
1667 memset(&pf, 0, sizeof(pf));
1668
1669 pf.apn = strdupReadString(p);
1670 pf.protocol = strdupReadString(p);
1671
1672 status = p.readInt32(&t);
1673 pf.authtype = (int) t;
1674
1675 pf.username = strdupReadString(p);
1676 pf.password = strdupReadString(p);
1677
1678 startRequest;
Etan Cohen5d891b72014-02-27 17:25:17 -08001679 appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
1680 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Sungmin Choi75697532013-04-26 15:04:45 -07001681 closeRequest;
1682 printRequest(pRI->token, pRI->pCI->requestNumber);
1683
1684 if (status != NO_ERROR) {
1685 goto invalid;
1686 }
Etan Cohend3652192014-06-20 08:28:44 -07001687 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Sungmin Choi75697532013-04-26 15:04:45 -07001688
1689#ifdef MEMSET_FREED
1690 memsetString(pf.apn);
1691 memsetString(pf.protocol);
1692 memsetString(pf.username);
1693 memsetString(pf.password);
1694#endif
1695
1696 free(pf.apn);
1697 free(pf.protocol);
1698 free(pf.username);
1699 free(pf.password);
1700
1701#ifdef MEMSET_FREED
1702 memset(&pf, 0, sizeof(pf));
1703#endif
1704
1705 return;
1706invalid:
1707 invalidCommandBlock(pRI);
1708 return;
1709}
1710
Jake Hamby8a4a2332014-01-15 13:12:05 -08001711static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1712 RIL_NV_ReadItem nvri;
1713 int32_t t;
1714 status_t status;
1715
1716 memset(&nvri, 0, sizeof(nvri));
1717
1718 status = p.readInt32(&t);
1719 nvri.itemID = (RIL_NV_Item) t;
1720
1721 if (status != NO_ERROR) {
1722 goto invalid;
1723 }
1724
1725 startRequest;
1726 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1727 closeRequest;
1728
1729 printRequest(pRI->token, pRI->pCI->requestNumber);
1730
Etan Cohend3652192014-06-20 08:28:44 -07001731 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001732
1733#ifdef MEMSET_FREED
1734 memset(&nvri, 0, sizeof(nvri));
1735#endif
1736
1737 return;
1738
1739invalid:
1740 invalidCommandBlock(pRI);
1741 return;
1742}
1743
1744static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1745 RIL_NV_WriteItem nvwi;
1746 int32_t t;
1747 status_t status;
1748
1749 memset(&nvwi, 0, sizeof(nvwi));
1750
1751 status = p.readInt32(&t);
1752 nvwi.itemID = (RIL_NV_Item) t;
1753
1754 nvwi.value = strdupReadString(p);
1755
1756 if (status != NO_ERROR || nvwi.value == NULL) {
1757 goto invalid;
1758 }
1759
1760 startRequest;
1761 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1762 nvwi.value);
1763 closeRequest;
1764
1765 printRequest(pRI->token, pRI->pCI->requestNumber);
1766
Etan Cohend3652192014-06-20 08:28:44 -07001767 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
Jake Hamby8a4a2332014-01-15 13:12:05 -08001768
1769#ifdef MEMSET_FREED
1770 memsetString(nvwi.value);
1771#endif
1772
1773 free(nvwi.value);
1774
1775#ifdef MEMSET_FREED
1776 memset(&nvwi, 0, sizeof(nvwi));
1777#endif
1778
1779 return;
1780
1781invalid:
1782 invalidCommandBlock(pRI);
1783 return;
1784}
1785
1786
Etan Cohend3652192014-06-20 08:28:44 -07001787static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1788 RIL_SelectUiccSub uicc_sub;
1789 status_t status;
1790 int32_t t;
1791 memset(&uicc_sub, 0, sizeof(uicc_sub));
1792
1793 status = p.readInt32(&t);
1794 if (status != NO_ERROR) {
1795 goto invalid;
1796 }
1797 uicc_sub.slot = (int) t;
1798
1799 status = p.readInt32(&t);
1800 if (status != NO_ERROR) {
1801 goto invalid;
1802 }
1803 uicc_sub.app_index = (int) t;
1804
1805 status = p.readInt32(&t);
1806 if (status != NO_ERROR) {
1807 goto invalid;
1808 }
1809 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1810
1811 status = p.readInt32(&t);
1812 if (status != NO_ERROR) {
1813 goto invalid;
1814 }
1815 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1816
1817 startRequest;
1818 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1819 uicc_sub.act_status);
1820 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1821 uicc_sub.app_index, uicc_sub.act_status);
1822 closeRequest;
1823 printRequest(pRI->token, pRI->pCI->requestNumber);
1824
1825 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1826
1827#ifdef MEMSET_FREED
1828 memset(&uicc_sub, 0, sizeof(uicc_sub));
1829#endif
1830 return;
1831
1832invalid:
1833 invalidCommandBlock(pRI);
1834 return;
1835}
1836
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001837static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001838blockingWrite(int fd, const void *buffer, size_t len) {
Wink Saville7f856802009-06-09 10:23:37 -07001839 size_t writeOffset = 0;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001840 const uint8_t *toWrite;
1841
1842 toWrite = (const uint8_t *)buffer;
1843
1844 while (writeOffset < len) {
1845 ssize_t written;
1846 do {
1847 written = write (fd, toWrite + writeOffset,
1848 len - writeOffset);
Banavathu, Srinivas Naik38884902011-07-05 20:04:25 +05301849 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001850
1851 if (written >= 0) {
1852 writeOffset += written;
1853 } else { // written < 0
Wink Saville8eb2a122012-11-19 16:05:13 -08001854 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001855 close(fd);
1856 return -1;
1857 }
1858 }
1859
1860 return 0;
1861}
1862
1863static int
Etan Cohend3652192014-06-20 08:28:44 -07001864sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
1865 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001866 int ret;
1867 uint32_t header;
Etan Cohend3652192014-06-20 08:28:44 -07001868 pthread_mutex_t * writeMutexHook = &s_writeMutex;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001869
Etan Cohend3652192014-06-20 08:28:44 -07001870 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
1871
1872#if (SIM_COUNT >= 2)
1873 if (socket_id == RIL_SOCKET_2) {
1874 fd = s_ril_param_socket2.fdCommand;
1875 writeMutexHook = &s_writeMutex_socket2;
1876 }
1877#if (SIM_COUNT >= 3)
1878 else if (socket_id == RIL_SOCKET_3) {
1879 fd = s_ril_param_socket3.fdCommand;
1880 writeMutexHook = &s_writeMutex_socket3;
1881 }
1882#endif
1883#if (SIM_COUNT >= 4)
1884 else if (socket_id == RIL_SOCKET_4) {
1885 fd = s_ril_param_socket4.fdCommand;
1886 writeMutexHook = &s_writeMutex_socket4;
1887 }
1888#endif
1889#endif
1890 if (fd < 0) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001891 return -1;
1892 }
1893
1894 if (dataSize > MAX_COMMAND_BYTES) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001895 RLOGE("RIL: packet larger than %u (%u)",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001896 MAX_COMMAND_BYTES, (unsigned int )dataSize);
1897
1898 return -1;
1899 }
Wink Saville7f856802009-06-09 10:23:37 -07001900
Etan Cohend3652192014-06-20 08:28:44 -07001901 pthread_mutex_lock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001902
1903 header = htonl(dataSize);
1904
1905 ret = blockingWrite(fd, (void *)&header, sizeof(header));
1906
1907 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07001908 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001909 return ret;
1910 }
1911
Kennyee1fadc2009-08-13 00:45:53 +08001912 ret = blockingWrite(fd, data, dataSize);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001913
1914 if (ret < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07001915 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001916 return ret;
1917 }
1918
Etan Cohend3652192014-06-20 08:28:44 -07001919 pthread_mutex_unlock(writeMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001920
1921 return 0;
1922}
1923
1924static int
Etan Cohend3652192014-06-20 08:28:44 -07001925sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001926 printResponse;
Etan Cohend3652192014-06-20 08:28:44 -07001927 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001928}
1929
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07001930/** response is an int* pointing to an array of ints */
Wink Saville7f856802009-06-09 10:23:37 -07001931
1932static int
Wink Savillef4c4d362009-04-02 01:37:03 -07001933responseInts(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001934 int numInts;
1935
1936 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001937 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001938 return RIL_ERRNO_INVALID_RESPONSE;
1939 }
1940 if (responselen % sizeof(int) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001941 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001942 (int)responselen, (int)sizeof(int));
1943 return RIL_ERRNO_INVALID_RESPONSE;
1944 }
1945
1946 int *p_int = (int *) response;
1947
Mohamad Ayyash74f7e662014-04-18 11:43:28 -07001948 numInts = responselen / sizeof(int);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001949 p.writeInt32 (numInts);
1950
1951 /* each int*/
1952 startResponse;
1953 for (int i = 0 ; i < numInts ; i++) {
1954 appendPrintBuf("%s%d,", printBuf, p_int[i]);
1955 p.writeInt32(p_int[i]);
1956 }
1957 removeLastChar;
1958 closeResponse;
1959
1960 return 0;
1961}
1962
Wink Saville43808972011-01-13 17:39:51 -08001963/** response is a char **, pointing to an array of char *'s
1964 The parcel will begin with the version */
1965static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
1966 p.writeInt32(version);
1967 return responseStrings(p, response, responselen);
1968}
1969
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001970/** response is a char **, pointing to an array of char *'s */
Wink Savillef4c4d362009-04-02 01:37:03 -07001971static int responseStrings(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001972 int numStrings;
Wink Saville7f856802009-06-09 10:23:37 -07001973
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001974 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001975 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001976 return RIL_ERRNO_INVALID_RESPONSE;
1977 }
1978 if (responselen % sizeof(char *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08001979 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08001980 (int)responselen, (int)sizeof(char *));
1981 return RIL_ERRNO_INVALID_RESPONSE;
1982 }
1983
1984 if (response == NULL) {
1985 p.writeInt32 (0);
1986 } else {
1987 char **p_cur = (char **) response;
1988
1989 numStrings = responselen / sizeof(char *);
1990 p.writeInt32 (numStrings);
1991
1992 /* each string*/
1993 startResponse;
1994 for (int i = 0 ; i < numStrings ; i++) {
1995 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
1996 writeStringToParcel (p, p_cur[i]);
1997 }
1998 removeLastChar;
1999 closeResponse;
2000 }
2001 return 0;
2002}
2003
2004
2005/**
Wink Saville7f856802009-06-09 10:23:37 -07002006 * NULL strings are accepted
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002007 * FIXME currently ignores responselen
2008 */
Wink Savillef4c4d362009-04-02 01:37:03 -07002009static int responseString(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002010 /* one string only */
2011 startResponse;
2012 appendPrintBuf("%s%s", printBuf, (char*)response);
2013 closeResponse;
2014
2015 writeStringToParcel(p, (const char *)response);
2016
2017 return 0;
2018}
2019
Wink Savillef4c4d362009-04-02 01:37:03 -07002020static int responseVoid(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002021 startResponse;
2022 removeLastChar;
2023 return 0;
2024}
2025
Wink Savillef4c4d362009-04-02 01:37:03 -07002026static int responseCallList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002027 int num;
2028
2029 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002030 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002031 return RIL_ERRNO_INVALID_RESPONSE;
2032 }
2033
2034 if (responselen % sizeof (RIL_Call *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002035 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002036 (int)responselen, (int)sizeof (RIL_Call *));
2037 return RIL_ERRNO_INVALID_RESPONSE;
2038 }
2039
2040 startResponse;
2041 /* number of call info's */
2042 num = responselen / sizeof(RIL_Call *);
2043 p.writeInt32(num);
2044
2045 for (int i = 0 ; i < num ; i++) {
2046 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2047 /* each call info */
2048 p.writeInt32(p_cur->state);
2049 p.writeInt32(p_cur->index);
2050 p.writeInt32(p_cur->toa);
2051 p.writeInt32(p_cur->isMpty);
2052 p.writeInt32(p_cur->isMT);
2053 p.writeInt32(p_cur->als);
2054 p.writeInt32(p_cur->isVoice);
Wink Saville1b5fd232009-04-22 14:50:00 -07002055 p.writeInt32(p_cur->isVoicePrivacy);
2056 writeStringToParcel(p, p_cur->number);
John Wangff368742009-03-24 17:56:29 -07002057 p.writeInt32(p_cur->numberPresentation);
Wink Saville1b5fd232009-04-22 14:50:00 -07002058 writeStringToParcel(p, p_cur->name);
2059 p.writeInt32(p_cur->namePresentation);
Wink Saville3a4840b2010-04-07 13:29:58 -07002060 // Remove when partners upgrade to version 3
Wink Saville74fa3882009-12-22 15:35:41 -08002061 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2062 p.writeInt32(0); /* UUS Information is absent */
2063 } else {
2064 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2065 p.writeInt32(1); /* UUS Information is present */
2066 p.writeInt32(uusInfo->uusType);
2067 p.writeInt32(uusInfo->uusDcs);
2068 p.writeInt32(uusInfo->uusLength);
2069 p.write(uusInfo->uusData, uusInfo->uusLength);
2070 }
Wink Saville3d54e742009-05-18 18:00:44 -07002071 appendPrintBuf("%s[id=%d,%s,toa=%d,",
John Wangff368742009-03-24 17:56:29 -07002072 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002073 p_cur->index,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002074 callStateToString(p_cur->state),
Wink Saville3d54e742009-05-18 18:00:44 -07002075 p_cur->toa);
2076 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2077 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002078 (p_cur->isMpty)?"conf":"norm",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002079 (p_cur->isMT)?"mt":"mo",
2080 p_cur->als,
2081 (p_cur->isVoice)?"voc":"nonvoc",
Wink Saville3d54e742009-05-18 18:00:44 -07002082 (p_cur->isVoicePrivacy)?"evp":"noevp");
2083 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2084 printBuf,
Wink Saville1b5fd232009-04-22 14:50:00 -07002085 p_cur->number,
2086 p_cur->numberPresentation,
2087 p_cur->name,
2088 p_cur->namePresentation);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002089 }
2090 removeLastChar;
2091 closeResponse;
2092
2093 return 0;
2094}
2095
Wink Savillef4c4d362009-04-02 01:37:03 -07002096static int responseSMS(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002097 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002098 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002099 return RIL_ERRNO_INVALID_RESPONSE;
2100 }
2101
2102 if (responselen != sizeof (RIL_SMS_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002103 RLOGE("invalid response length %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002104 (int)responselen, (int)sizeof (RIL_SMS_Response));
2105 return RIL_ERRNO_INVALID_RESPONSE;
2106 }
2107
2108 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2109
2110 p.writeInt32(p_cur->messageRef);
2111 writeStringToParcel(p, p_cur->ackPDU);
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002112 p.writeInt32(p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002113
2114 startResponse;
Jaikumar Ganesh920c78f2009-06-04 10:53:15 -07002115 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2116 (char*)p_cur->ackPDU, p_cur->errorCode);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002117 closeResponse;
2118
2119 return 0;
2120}
2121
Wink Savillec0114b32011-02-18 10:14:07 -08002122static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002123{
2124 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002125 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002126 return RIL_ERRNO_INVALID_RESPONSE;
2127 }
2128
Wink Savillec0114b32011-02-18 10:14:07 -08002129 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002130 RLOGE("invalid response length %d expected multiple of %d",
Wink Savillec0114b32011-02-18 10:14:07 -08002131 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002132 return RIL_ERRNO_INVALID_RESPONSE;
2133 }
2134
Wink Savillec0114b32011-02-18 10:14:07 -08002135 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002136 p.writeInt32(num);
2137
Wink Savillec0114b32011-02-18 10:14:07 -08002138 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002139 startResponse;
2140 int i;
2141 for (i = 0; i < num; i++) {
2142 p.writeInt32(p_cur[i].cid);
2143 p.writeInt32(p_cur[i].active);
2144 writeStringToParcel(p, p_cur[i].type);
Wink Savillec0114b32011-02-18 10:14:07 -08002145 // apn is not used, so don't send.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002146 writeStringToParcel(p, p_cur[i].address);
Wink Savillec0114b32011-02-18 10:14:07 -08002147 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002148 p_cur[i].cid,
2149 (p_cur[i].active==0)?"down":"up",
2150 (char*)p_cur[i].type,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002151 (char*)p_cur[i].address);
2152 }
2153 removeLastChar;
2154 closeResponse;
2155
2156 return 0;
2157}
2158
Etan Cohend3652192014-06-20 08:28:44 -07002159static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2160{
2161 if (response == NULL && responselen != 0) {
2162 RLOGE("invalid response: NULL");
2163 return RIL_ERRNO_INVALID_RESPONSE;
2164 }
2165
2166 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2167 RLOGE("invalid response length %d expected multiple of %d",
2168 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2169 return RIL_ERRNO_INVALID_RESPONSE;
2170 }
2171
2172 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2173 p.writeInt32(num);
2174
2175 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2176 startResponse;
2177 int i;
2178 for (i = 0; i < num; i++) {
2179 p.writeInt32((int)p_cur[i].status);
2180 p.writeInt32(p_cur[i].suggestedRetryTime);
2181 p.writeInt32(p_cur[i].cid);
2182 p.writeInt32(p_cur[i].active);
2183 writeStringToParcel(p, p_cur[i].type);
2184 writeStringToParcel(p, p_cur[i].ifname);
2185 writeStringToParcel(p, p_cur[i].addresses);
2186 writeStringToParcel(p, p_cur[i].dnses);
2187 writeStringToParcel(p, p_cur[i].gateways);
2188 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2189 p_cur[i].status,
2190 p_cur[i].suggestedRetryTime,
2191 p_cur[i].cid,
2192 (p_cur[i].active==0)?"down":"up",
2193 (char*)p_cur[i].type,
2194 (char*)p_cur[i].ifname,
2195 (char*)p_cur[i].addresses,
2196 (char*)p_cur[i].dnses,
2197 (char*)p_cur[i].gateways);
2198 }
2199 removeLastChar;
2200 closeResponse;
2201
2202 return 0;
2203}
2204
Wink Saville43808972011-01-13 17:39:51 -08002205static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2206{
2207 // Write version
2208 p.writeInt32(s_callbacks.version);
2209
2210 if (s_callbacks.version < 5) {
Wink Savillec0114b32011-02-18 10:14:07 -08002211 return responseDataCallListV4(p, response, responselen);
Wink Saville43808972011-01-13 17:39:51 -08002212 } else {
2213 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002214 RLOGE("invalid response: NULL");
Wink Saville43808972011-01-13 17:39:51 -08002215 return RIL_ERRNO_INVALID_RESPONSE;
2216 }
2217
Etan Cohend3652192014-06-20 08:28:44 -07002218 // Support v6 or v9 with new rils
2219 if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2220 return responseDataCallListV6(p, response, responselen);
2221 }
2222
2223 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002224 RLOGE("invalid response length %d expected multiple of %d",
Etan Cohend3652192014-06-20 08:28:44 -07002225 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
Wink Saville43808972011-01-13 17:39:51 -08002226 return RIL_ERRNO_INVALID_RESPONSE;
2227 }
2228
Etan Cohend3652192014-06-20 08:28:44 -07002229 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
Wink Saville43808972011-01-13 17:39:51 -08002230 p.writeInt32(num);
2231
Etan Cohend3652192014-06-20 08:28:44 -07002232 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
Wink Saville43808972011-01-13 17:39:51 -08002233 startResponse;
2234 int i;
2235 for (i = 0; i < num; i++) {
2236 p.writeInt32((int)p_cur[i].status);
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002237 p.writeInt32(p_cur[i].suggestedRetryTime);
Wink Saville43808972011-01-13 17:39:51 -08002238 p.writeInt32(p_cur[i].cid);
2239 p.writeInt32(p_cur[i].active);
David 'Digit' Turneraf1298d2011-02-04 13:36:47 +01002240 writeStringToParcel(p, p_cur[i].type);
Wink Saville43808972011-01-13 17:39:51 -08002241 writeStringToParcel(p, p_cur[i].ifname);
2242 writeStringToParcel(p, p_cur[i].addresses);
2243 writeStringToParcel(p, p_cur[i].dnses);
Wink Savillec0114b32011-02-18 10:14:07 -08002244 writeStringToParcel(p, p_cur[i].gateways);
Etan Cohend3652192014-06-20 08:28:44 -07002245 writeStringToParcel(p, p_cur[i].pcscf);
2246 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
Wink Saville43808972011-01-13 17:39:51 -08002247 p_cur[i].status,
Kazuhiro Ondobeb25b52011-06-17 16:26:45 -05002248 p_cur[i].suggestedRetryTime,
Wink Saville43808972011-01-13 17:39:51 -08002249 p_cur[i].cid,
2250 (p_cur[i].active==0)?"down":"up",
Naveen Kalla56384152011-11-16 11:12:37 -08002251 (char*)p_cur[i].type,
Wink Saville43808972011-01-13 17:39:51 -08002252 (char*)p_cur[i].ifname,
2253 (char*)p_cur[i].addresses,
Wink Savillec0114b32011-02-18 10:14:07 -08002254 (char*)p_cur[i].dnses,
Etan Cohend3652192014-06-20 08:28:44 -07002255 (char*)p_cur[i].gateways,
2256 (char*)p_cur[i].pcscf);
Wink Saville43808972011-01-13 17:39:51 -08002257 }
2258 removeLastChar;
2259 closeResponse;
2260 }
2261
2262 return 0;
2263}
2264
2265static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2266{
2267 if (s_callbacks.version < 5) {
2268 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2269 } else {
2270 return responseDataCallList(p, response, responselen);
2271 }
2272}
2273
Wink Savillef4c4d362009-04-02 01:37:03 -07002274static int responseRaw(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002275 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002276 RLOGE("invalid response: NULL with responselen != 0");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002277 return RIL_ERRNO_INVALID_RESPONSE;
2278 }
2279
2280 // The java code reads -1 size as null byte array
2281 if (response == NULL) {
Wink Saville7f856802009-06-09 10:23:37 -07002282 p.writeInt32(-1);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002283 } else {
2284 p.writeInt32(responselen);
2285 p.write(response, responselen);
2286 }
2287
2288 return 0;
2289}
2290
2291
Wink Savillef4c4d362009-04-02 01:37:03 -07002292static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002293 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002294 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297
2298 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002299 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002300 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2301 return RIL_ERRNO_INVALID_RESPONSE;
2302 }
2303
2304 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2305 p.writeInt32(p_cur->sw1);
2306 p.writeInt32(p_cur->sw2);
2307 writeStringToParcel(p, p_cur->simResponse);
2308
2309 startResponse;
2310 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2311 (char*)p_cur->simResponse);
2312 closeResponse;
2313
2314
2315 return 0;
2316}
2317
Wink Savillef4c4d362009-04-02 01:37:03 -07002318static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002319 int num;
Wink Saville7f856802009-06-09 10:23:37 -07002320
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002321 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002322 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002323 return RIL_ERRNO_INVALID_RESPONSE;
2324 }
2325
2326 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002327 RLOGE("invalid response length %d expected multiple of %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002328 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2329 return RIL_ERRNO_INVALID_RESPONSE;
2330 }
2331
2332 /* number of call info's */
2333 num = responselen / sizeof(RIL_CallForwardInfo *);
2334 p.writeInt32(num);
2335
2336 startResponse;
2337 for (int i = 0 ; i < num ; i++) {
2338 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2339
2340 p.writeInt32(p_cur->status);
2341 p.writeInt32(p_cur->reason);
2342 p.writeInt32(p_cur->serviceClass);
2343 p.writeInt32(p_cur->toa);
2344 writeStringToParcel(p, p_cur->number);
2345 p.writeInt32(p_cur->timeSeconds);
2346 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2347 (p_cur->status==1)?"enable":"disable",
2348 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2349 (char*)p_cur->number,
2350 p_cur->timeSeconds);
2351 }
2352 removeLastChar;
2353 closeResponse;
Wink Saville7f856802009-06-09 10:23:37 -07002354
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002355 return 0;
2356}
2357
Wink Savillef4c4d362009-04-02 01:37:03 -07002358static int responseSsn(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002359 if (response == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002360 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002361 return RIL_ERRNO_INVALID_RESPONSE;
2362 }
2363
2364 if (responselen != sizeof(RIL_SuppSvcNotification)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002365 RLOGE("invalid response length was %d expected %d",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002366 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2367 return RIL_ERRNO_INVALID_RESPONSE;
2368 }
2369
2370 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2371 p.writeInt32(p_cur->notificationType);
2372 p.writeInt32(p_cur->code);
2373 p.writeInt32(p_cur->index);
2374 p.writeInt32(p_cur->type);
2375 writeStringToParcel(p, p_cur->number);
2376
2377 startResponse;
2378 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2379 (p_cur->notificationType==0)?"mo":"mt",
2380 p_cur->code, p_cur->index, p_cur->type,
2381 (char*)p_cur->number);
2382 closeResponse;
2383
2384 return 0;
2385}
2386
Wink Saville3d54e742009-05-18 18:00:44 -07002387static int responseCellList(Parcel &p, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002388 int num;
2389
2390 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002391 RLOGE("invalid response: NULL");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002392 return RIL_ERRNO_INVALID_RESPONSE;
2393 }
2394
2395 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002396 RLOGE("invalid response length %d expected multiple of %d\n",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002397 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2398 return RIL_ERRNO_INVALID_RESPONSE;
2399 }
2400
2401 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002402 /* number of records */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002403 num = responselen / sizeof(RIL_NeighboringCell *);
2404 p.writeInt32(num);
2405
2406 for (int i = 0 ; i < num ; i++) {
2407 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2408
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08002409 p.writeInt32(p_cur->rssi);
2410 writeStringToParcel (p, p_cur->cid);
2411
2412 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2413 p_cur->cid, p_cur->rssi);
2414 }
2415 removeLastChar;
2416 closeResponse;
2417
2418 return 0;
2419}
2420
Wink Saville3d54e742009-05-18 18:00:44 -07002421/**
2422 * Marshall the signalInfoRecord into the parcel if it exists.
2423 */
Wink Savillea592eeb2009-05-22 13:26:36 -07002424static void marshallSignalInfoRecord(Parcel &p,
2425 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
Wink Saville3d54e742009-05-18 18:00:44 -07002426 p.writeInt32(p_signalInfoRecord.isPresent);
2427 p.writeInt32(p_signalInfoRecord.signalType);
2428 p.writeInt32(p_signalInfoRecord.alertPitch);
2429 p.writeInt32(p_signalInfoRecord.signal);
2430}
2431
Wink Savillea592eeb2009-05-22 13:26:36 -07002432static int responseCdmaInformationRecords(Parcel &p,
2433 void *response, size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002434 int num;
Wink Savillea592eeb2009-05-22 13:26:36 -07002435 char* string8 = NULL;
2436 int buffer_lenght;
2437 RIL_CDMA_InformationRecord *infoRec;
Wink Saville3d54e742009-05-18 18:00:44 -07002438
2439 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002440 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002441 return RIL_ERRNO_INVALID_RESPONSE;
2442 }
2443
Wink Savillea592eeb2009-05-22 13:26:36 -07002444 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002445 RLOGE("invalid response length %d expected multiple of %d\n",
Wink Savillea592eeb2009-05-22 13:26:36 -07002446 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
Wink Saville3d54e742009-05-18 18:00:44 -07002447 return RIL_ERRNO_INVALID_RESPONSE;
2448 }
2449
Wink Savillea592eeb2009-05-22 13:26:36 -07002450 RIL_CDMA_InformationRecords *p_cur =
2451 (RIL_CDMA_InformationRecords *) response;
2452 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
Wink Saville3d54e742009-05-18 18:00:44 -07002453
2454 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002455 p.writeInt32(num);
Wink Saville3d54e742009-05-18 18:00:44 -07002456
Wink Savillea592eeb2009-05-22 13:26:36 -07002457 for (int i = 0 ; i < num ; i++) {
2458 infoRec = &p_cur->infoRec[i];
2459 p.writeInt32(infoRec->name);
2460 switch (infoRec->name) {
Wink Saville3d54e742009-05-18 18:00:44 -07002461 case RIL_CDMA_DISPLAY_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002462 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2463 if (infoRec->rec.display.alpha_len >
2464 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002465 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002466 expected not more than %d\n",
2467 (int)infoRec->rec.display.alpha_len,
2468 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2469 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002470 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002471 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2472 * sizeof(char) );
2473 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2474 string8[i] = infoRec->rec.display.alpha_buf[i];
2475 }
Wink Saville43808972011-01-13 17:39:51 -08002476 string8[(int)infoRec->rec.display.alpha_len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002477 writeStringToParcel(p, (const char*)string8);
2478 free(string8);
2479 string8 = NULL;
Wink Saville3d54e742009-05-18 18:00:44 -07002480 break;
2481 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002482 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
Wink Saville3d54e742009-05-18 18:00:44 -07002483 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002484 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002485 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002486 expected not more than %d\n",
2487 (int)infoRec->rec.number.len,
2488 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2489 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002490 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002491 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2492 * sizeof(char) );
2493 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2494 string8[i] = infoRec->rec.number.buf[i];
2495 }
Wink Saville43808972011-01-13 17:39:51 -08002496 string8[(int)infoRec->rec.number.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002497 writeStringToParcel(p, (const char*)string8);
2498 free(string8);
2499 string8 = NULL;
2500 p.writeInt32(infoRec->rec.number.number_type);
2501 p.writeInt32(infoRec->rec.number.number_plan);
2502 p.writeInt32(infoRec->rec.number.pi);
2503 p.writeInt32(infoRec->rec.number.si);
Wink Saville3d54e742009-05-18 18:00:44 -07002504 break;
2505 case RIL_CDMA_SIGNAL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002506 p.writeInt32(infoRec->rec.signal.isPresent);
2507 p.writeInt32(infoRec->rec.signal.signalType);
2508 p.writeInt32(infoRec->rec.signal.alertPitch);
2509 p.writeInt32(infoRec->rec.signal.signal);
2510
2511 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2512 alertPitch=%X, signal=%X, ",
2513 printBuf, (int)infoRec->rec.signal.isPresent,
2514 (int)infoRec->rec.signal.signalType,
2515 (int)infoRec->rec.signal.alertPitch,
2516 (int)infoRec->rec.signal.signal);
2517 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002518 break;
2519 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002520 if (infoRec->rec.redir.redirectingNumber.len >
2521 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002522 RLOGE("invalid display info response length %d \
Wink Savillea592eeb2009-05-22 13:26:36 -07002523 expected not more than %d\n",
2524 (int)infoRec->rec.redir.redirectingNumber.len,
2525 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2526 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002527 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002528 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2529 .len + 1) * sizeof(char) );
2530 for (int i = 0;
2531 i < infoRec->rec.redir.redirectingNumber.len;
2532 i++) {
2533 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2534 }
Wink Saville43808972011-01-13 17:39:51 -08002535 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
Wink Savillea592eeb2009-05-22 13:26:36 -07002536 writeStringToParcel(p, (const char*)string8);
2537 free(string8);
2538 string8 = NULL;
2539 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2540 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2541 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2542 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2543 p.writeInt32(infoRec->rec.redir.redirectingReason);
Wink Saville3d54e742009-05-18 18:00:44 -07002544 break;
2545 case RIL_CDMA_LINE_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002546 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2547 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2548 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2549 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2550
2551 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2552 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2553 lineCtrlPowerDenial=%d, ", printBuf,
2554 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2555 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2556 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2557 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2558 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002559 break;
2560 case RIL_CDMA_T53_CLIR_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002561 p.writeInt32((int)(infoRec->rec.clir.cause));
Wink Saville3d54e742009-05-18 18:00:44 -07002562
Wink Savillea592eeb2009-05-22 13:26:36 -07002563 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2564 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002565 break;
2566 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
Wink Savillea592eeb2009-05-22 13:26:36 -07002567 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2568 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2569
2570 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2571 infoRec->rec.audioCtrl.upLink,
2572 infoRec->rec.audioCtrl.downLink);
2573 removeLastChar;
Wink Saville3d54e742009-05-18 18:00:44 -07002574 break;
Wink Savillea592eeb2009-05-22 13:26:36 -07002575 case RIL_CDMA_T53_RELEASE_INFO_REC:
2576 // TODO(Moto): See David Krause, he has the answer:)
Wink Saville8eb2a122012-11-19 16:05:13 -08002577 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Wink Savillea592eeb2009-05-22 13:26:36 -07002578 return RIL_ERRNO_INVALID_RESPONSE;
2579 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08002580 RLOGE("Incorrect name value");
Wink Savillea592eeb2009-05-22 13:26:36 -07002581 return RIL_ERRNO_INVALID_RESPONSE;
Wink Saville3d54e742009-05-18 18:00:44 -07002582 }
2583 }
Wink Savillea592eeb2009-05-22 13:26:36 -07002584 closeResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002585
Wink Savillea592eeb2009-05-22 13:26:36 -07002586 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07002587}
2588
Wink Savillea592eeb2009-05-22 13:26:36 -07002589static int responseRilSignalStrength(Parcel &p,
2590 void *response, size_t responselen) {
2591 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002592 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002593 return RIL_ERRNO_INVALID_RESPONSE;
2594 }
2595
Wink Savillec0114b32011-02-18 10:14:07 -08002596 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Etan Cohend3652192014-06-20 08:28:44 -07002597 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Wink Saville3d54e742009-05-18 18:00:44 -07002598
Wink Saville3d54e742009-05-18 18:00:44 -07002599 p.writeInt32(p_cur->GW_SignalStrength.signalStrength);
2600 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
2601 p.writeInt32(p_cur->CDMA_SignalStrength.dbm);
2602 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
2603 p.writeInt32(p_cur->EVDO_SignalStrength.dbm);
2604 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
2605 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Wink Savillec0114b32011-02-18 10:14:07 -08002606 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002607 /*
Wink Saville18e4ab12013-04-07 17:31:04 -07002608 * Fixup LTE for backwards compatibility
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002609 */
Wink Saville18e4ab12013-04-07 17:31:04 -07002610 if (s_callbacks.version <= 6) {
2611 // signalStrength: -1 -> 99
2612 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
2613 p_cur->LTE_SignalStrength.signalStrength = 99;
2614 }
2615 // rsrp: -1 -> INT_MAX all other negative value to positive.
2616 // So remap here
2617 if (p_cur->LTE_SignalStrength.rsrp == -1) {
2618 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
2619 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
2620 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
2621 }
2622 // rsrq: -1 -> INT_MAX
2623 if (p_cur->LTE_SignalStrength.rsrq == -1) {
2624 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
2625 }
2626 // Not remapping rssnr is already using INT_MAX
Uma Maheswari Ramalingam9efcac52012-08-09 11:59:17 -07002627
Wink Saville18e4ab12013-04-07 17:31:04 -07002628 // cqi: -1 -> INT_MAX
2629 if (p_cur->LTE_SignalStrength.cqi == -1) {
2630 p_cur->LTE_SignalStrength.cqi = INT_MAX;
2631 }
2632 }
2633 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Wink Savillec0114b32011-02-18 10:14:07 -08002634 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
2635 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
2636 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
2637 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Etan Cohend3652192014-06-20 08:28:44 -07002638 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
2639 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
2640 } else {
2641 p.writeInt32(INT_MAX);
2642 }
Wink Savillec0114b32011-02-18 10:14:07 -08002643 } else {
Wink Saville18e4ab12013-04-07 17:31:04 -07002644 p.writeInt32(99);
2645 p.writeInt32(INT_MAX);
2646 p.writeInt32(INT_MAX);
2647 p.writeInt32(INT_MAX);
2648 p.writeInt32(INT_MAX);
Etan Cohend3652192014-06-20 08:28:44 -07002649 p.writeInt32(INT_MAX);
Wink Savillec0114b32011-02-18 10:14:07 -08002650 }
johnwangfdf825f2009-05-22 15:50:34 -07002651
2652 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07002653 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
Wink Savillec0114b32011-02-18 10:14:07 -08002654 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
2655 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
2656 EVDO_SS.signalNoiseRatio=%d,\
2657 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Etan Cohend3652192014-06-20 08:28:44 -07002658 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Wink Savillea592eeb2009-05-22 13:26:36 -07002659 printBuf,
2660 p_cur->GW_SignalStrength.signalStrength,
2661 p_cur->GW_SignalStrength.bitErrorRate,
2662 p_cur->CDMA_SignalStrength.dbm,
2663 p_cur->CDMA_SignalStrength.ecio,
2664 p_cur->EVDO_SignalStrength.dbm,
2665 p_cur->EVDO_SignalStrength.ecio,
Wink Savillec0114b32011-02-18 10:14:07 -08002666 p_cur->EVDO_SignalStrength.signalNoiseRatio,
2667 p_cur->LTE_SignalStrength.signalStrength,
2668 p_cur->LTE_SignalStrength.rsrp,
2669 p_cur->LTE_SignalStrength.rsrq,
2670 p_cur->LTE_SignalStrength.rssnr,
Etan Cohend3652192014-06-20 08:28:44 -07002671 p_cur->LTE_SignalStrength.cqi,
2672 p_cur->TD_SCDMA_SignalStrength.rscp);
Wink Savillea592eeb2009-05-22 13:26:36 -07002673 closeResponse;
2674
Wink Saville3d54e742009-05-18 18:00:44 -07002675 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08002676 RLOGE("invalid response length");
Wink Saville3d54e742009-05-18 18:00:44 -07002677 return RIL_ERRNO_INVALID_RESPONSE;
2678 }
2679
Wink Saville3d54e742009-05-18 18:00:44 -07002680 return 0;
2681}
2682
2683static int responseCallRing(Parcel &p, void *response, size_t responselen) {
2684 if ((response == NULL) || (responselen == 0)) {
2685 return responseVoid(p, response, responselen);
2686 } else {
2687 return responseCdmaSignalInfoRecord(p, response, responselen);
2688 }
2689}
2690
2691static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
2692 if (response == NULL || responselen == 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002693 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002694 return RIL_ERRNO_INVALID_RESPONSE;
2695 }
2696
2697 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002698 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Wink Saville3d54e742009-05-18 18:00:44 -07002699 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
2700 return RIL_ERRNO_INVALID_RESPONSE;
2701 }
2702
2703 startResponse;
2704
2705 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
2706 marshallSignalInfoRecord(p, *p_cur);
2707
2708 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
2709 signal=%d]",
2710 printBuf,
2711 p_cur->isPresent,
2712 p_cur->signalType,
2713 p_cur->alertPitch,
2714 p_cur->signal);
2715
2716 closeResponse;
2717 return 0;
2718}
2719
Wink Savillea592eeb2009-05-22 13:26:36 -07002720static int responseCdmaCallWaiting(Parcel &p, void *response,
2721 size_t responselen) {
Wink Saville3d54e742009-05-18 18:00:44 -07002722 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002723 RLOGE("invalid response: NULL");
Wink Saville3d54e742009-05-18 18:00:44 -07002724 return RIL_ERRNO_INVALID_RESPONSE;
2725 }
2726
Wink Savillec0114b32011-02-18 10:14:07 -08002727 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002728 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Wink Savillec0114b32011-02-18 10:14:07 -08002729 }
2730
2731 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
2732
2733 writeStringToParcel(p, p_cur->number);
2734 p.writeInt32(p_cur->numberPresentation);
2735 writeStringToParcel(p, p_cur->name);
2736 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
2737
2738 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
2739 p.writeInt32(p_cur->number_type);
2740 p.writeInt32(p_cur->number_plan);
2741 } else {
2742 p.writeInt32(0);
2743 p.writeInt32(0);
Wink Saville3d54e742009-05-18 18:00:44 -07002744 }
2745
2746 startResponse;
Wink Saville3d54e742009-05-18 18:00:44 -07002747 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
2748 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
Wink Savillec0114b32011-02-18 10:14:07 -08002749 signal=%d,number_type=%d,number_plan=%d]",
Wink Saville3d54e742009-05-18 18:00:44 -07002750 printBuf,
2751 p_cur->number,
2752 p_cur->numberPresentation,
2753 p_cur->name,
2754 p_cur->signalInfoRecord.isPresent,
2755 p_cur->signalInfoRecord.signalType,
2756 p_cur->signalInfoRecord.alertPitch,
Wink Savillec0114b32011-02-18 10:14:07 -08002757 p_cur->signalInfoRecord.signal,
2758 p_cur->number_type,
2759 p_cur->number_plan);
Wink Saville3d54e742009-05-18 18:00:44 -07002760 closeResponse;
2761
2762 return 0;
2763}
2764
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002765static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
2766 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08002767 RLOGE("responseSimRefresh: invalid response: NULL");
Alex Yakavenka45e740e2012-01-31 11:48:27 -08002768 return RIL_ERRNO_INVALID_RESPONSE;
2769 }
2770
2771 startResponse;
2772 if (s_callbacks.version == 7) {
2773 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
2774 p.writeInt32(p_cur->result);
2775 p.writeInt32(p_cur->ef_id);
2776 writeStringToParcel(p, p_cur->aid);
2777
2778 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
2779 printBuf,
2780 p_cur->result,
2781 p_cur->ef_id,
2782 p_cur->aid);
2783 } else {
2784 int *p_cur = ((int *) response);
2785 p.writeInt32(p_cur[0]);
2786 p.writeInt32(p_cur[1]);
2787 writeStringToParcel(p, NULL);
2788
2789 appendPrintBuf("%sresult=%d, ef_id=%d",
2790 printBuf,
2791 p_cur[0],
2792 p_cur[1]);
2793 }
2794 closeResponse;
2795
2796 return 0;
2797}
2798
Wink Saville8a9e0212013-04-09 12:11:38 -07002799static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
2800{
2801 if (response == NULL && responselen != 0) {
2802 RLOGE("invalid response: NULL");
2803 return RIL_ERRNO_INVALID_RESPONSE;
2804 }
2805
2806 if (responselen % sizeof(RIL_CellInfo) != 0) {
2807 RLOGE("invalid response length %d expected multiple of %d",
2808 (int)responselen, (int)sizeof(RIL_CellInfo));
2809 return RIL_ERRNO_INVALID_RESPONSE;
2810 }
2811
2812 int num = responselen / sizeof(RIL_CellInfo);
2813 p.writeInt32(num);
2814
2815 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
2816 startResponse;
2817 int i;
2818 for (i = 0; i < num; i++) {
2819 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
2820 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
2821 p.writeInt32((int)p_cur->cellInfoType);
2822 p.writeInt32(p_cur->registered);
2823 p.writeInt32(p_cur->timeStampType);
2824 p.writeInt64(p_cur->timeStamp);
2825 switch(p_cur->cellInfoType) {
2826 case RIL_CELL_INFO_TYPE_GSM: {
Wink Savillec57b3eb2013-04-17 12:51:41 -07002827 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002828 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
2829 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
2830 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
Wink Savillec57b3eb2013-04-17 12:51:41 -07002831 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
2832 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
Wink Saville8a9e0212013-04-09 12:11:38 -07002833 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
2834 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2835
2836 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
2837 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
2838 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
2839 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
Wink Saville8a9e0212013-04-09 12:11:38 -07002840 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
2841 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
2842 break;
2843 }
Wink Savillec57b3eb2013-04-17 12:51:41 -07002844 case RIL_CELL_INFO_TYPE_WCDMA: {
2845 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
2846 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
2847 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
2848 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
2849 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
2850 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2851 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
2852 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
2853 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2854
2855 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
2856 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
2857 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
2858 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
2859 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
2860 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
2861 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
2862 break;
2863 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002864 case RIL_CELL_INFO_TYPE_CDMA: {
2865 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
2866 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
2867 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
2868 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
2869 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
2870 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2871
2872 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
2873 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
2874 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
2875 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
2876 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
2877
2878 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
2879 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
2880 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
2881 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
2882 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
2883 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2884
2885 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
2886 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
2887 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
2888 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
2889 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
2890 break;
2891 }
2892 case RIL_CELL_INFO_TYPE_LTE: {
2893 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
2894 p_cur->CellInfo.lte.cellIdentityLte.mcc,
2895 p_cur->CellInfo.lte.cellIdentityLte.mnc,
2896 p_cur->CellInfo.lte.cellIdentityLte.ci,
2897 p_cur->CellInfo.lte.cellIdentityLte.pci,
2898 p_cur->CellInfo.lte.cellIdentityLte.tac);
2899
2900 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
2901 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
2902 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
2903 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
2904 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
2905
2906 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
2907 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
2908 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
2909 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
2910 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
2911 p_cur->CellInfo.lte.signalStrengthLte.cqi,
2912 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2913 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
2914 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
2915 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
2916 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
2917 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
2918 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
2919 break;
2920 }
Etan Cohend3652192014-06-20 08:28:44 -07002921 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
2922 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
2923 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
2924 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
2925 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
2926 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
2927 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
2928 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
2929 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
2930
2931 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
2932 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
2933 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
2934 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
2935 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
2936 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
2937 break;
2938 }
Wink Saville8a9e0212013-04-09 12:11:38 -07002939 }
2940 p_cur += 1;
2941 }
2942 removeLastChar;
2943 closeResponse;
2944
2945 return 0;
2946}
2947
Etan Cohend3652192014-06-20 08:28:44 -07002948static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
2949{
2950 if (response == NULL && responselen != 0) {
2951 RLOGE("invalid response: NULL");
2952 return RIL_ERRNO_INVALID_RESPONSE;
2953 }
2954
2955 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
2956 RLOGE("invalid response length %d expected multiple of %d",
2957 (int)responselen, (int)sizeof(RIL_HardwareConfig));
2958 return RIL_ERRNO_INVALID_RESPONSE;
2959 }
2960
2961 int num = responselen / sizeof(RIL_HardwareConfig);
2962 int i;
2963 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
2964
2965 p.writeInt32(num);
2966
2967 startResponse;
2968 for (i = 0; i < num; i++) {
2969 switch (p_cur[i].type) {
2970 case RIL_HARDWARE_CONFIG_MODEM: {
2971 writeStringToParcel(p, p_cur[i].uuid);
2972 p.writeInt32((int)p_cur[i].state);
2973 p.writeInt32(p_cur[i].cfg.modem.rat);
2974 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
2975 p.writeInt32(p_cur[i].cfg.modem.maxData);
2976 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
2977
2978 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
2979 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
2980 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
2981 break;
2982 }
2983 case RIL_HARDWARE_CONFIG_SIM: {
2984 writeStringToParcel(p, p_cur[i].uuid);
2985 p.writeInt32((int)p_cur[i].state);
2986 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
2987
2988 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
2989 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
2990 break;
2991 }
2992 }
2993 }
2994 removeLastChar;
2995 closeResponse;
2996 return 0;
2997}
2998
Wink Saville3d54e742009-05-18 18:00:44 -07002999static void triggerEvLoop() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003000 int ret;
3001 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3002 /* trigger event loop to wakeup. No reason to do this,
3003 * if we're in the event loop thread */
3004 do {
3005 ret = write (s_fdWakeupWrite, " ", 1);
3006 } while (ret < 0 && errno == EINTR);
3007 }
3008}
3009
Wink Saville3d54e742009-05-18 18:00:44 -07003010static void rilEventAddWakeup(struct ril_event *ev) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003011 ril_event_add(ev);
3012 triggerEvLoop();
3013}
3014
Wink Savillefd729372011-02-22 16:19:39 -08003015static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3016 p.writeInt32(num_apps);
3017 startResponse;
3018 for (int i = 0; i < num_apps; i++) {
3019 p.writeInt32(appStatus[i].app_type);
3020 p.writeInt32(appStatus[i].app_state);
3021 p.writeInt32(appStatus[i].perso_substate);
3022 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3023 writeStringToParcel(p, (const char*)
3024 (appStatus[i].app_label_ptr));
3025 p.writeInt32(appStatus[i].pin1_replaced);
3026 p.writeInt32(appStatus[i].pin1);
3027 p.writeInt32(appStatus[i].pin2);
3028 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3029 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3030 printBuf,
3031 appStatus[i].app_type,
3032 appStatus[i].app_state,
3033 appStatus[i].perso_substate,
3034 appStatus[i].aid_ptr,
3035 appStatus[i].app_label_ptr,
3036 appStatus[i].pin1_replaced,
3037 appStatus[i].pin1,
3038 appStatus[i].pin2);
3039 }
3040 closeResponse;
3041}
3042
Wink Savillef4c4d362009-04-02 01:37:03 -07003043static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
3044 int i;
3045
3046 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003047 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003048 return RIL_ERRNO_INVALID_RESPONSE;
3049 }
3050
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003051 if (responselen == sizeof (RIL_CardStatus_v6)) {
Wink Savillefd729372011-02-22 16:19:39 -08003052 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
Wink Savillef4c4d362009-04-02 01:37:03 -07003053
Wink Savillefd729372011-02-22 16:19:39 -08003054 p.writeInt32(p_cur->card_state);
3055 p.writeInt32(p_cur->universal_pin_state);
3056 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3057 p.writeInt32(p_cur->cdma_subscription_app_index);
3058 p.writeInt32(p_cur->ims_subscription_app_index);
3059
3060 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003061 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Wink Savillefd729372011-02-22 16:19:39 -08003062 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3063
3064 p.writeInt32(p_cur->card_state);
3065 p.writeInt32(p_cur->universal_pin_state);
3066 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3067 p.writeInt32(p_cur->cdma_subscription_app_index);
3068 p.writeInt32(-1);
3069
3070 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003071 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003072 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Wink Saville2c1fb3a2011-03-19 13:42:45 -07003073 return RIL_ERRNO_INVALID_RESPONSE;
Wink Savillef4c4d362009-04-02 01:37:03 -07003074 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003075
3076 return 0;
Wink Saville3d54e742009-05-18 18:00:44 -07003077}
Wink Savillef4c4d362009-04-02 01:37:03 -07003078
Wink Savillea592eeb2009-05-22 13:26:36 -07003079static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3080 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
Wink Savillef4c4d362009-04-02 01:37:03 -07003081 p.writeInt32(num);
3082
Wink Savillef4c4d362009-04-02 01:37:03 -07003083 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003084 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3085 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3086 for (int i = 0; i < num; i++) {
3087 p.writeInt32(p_cur[i]->fromServiceId);
3088 p.writeInt32(p_cur[i]->toServiceId);
3089 p.writeInt32(p_cur[i]->fromCodeScheme);
3090 p.writeInt32(p_cur[i]->toCodeScheme);
3091 p.writeInt32(p_cur[i]->selected);
3092
3093 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3094 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3095 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3096 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3097 p_cur[i]->selected);
3098 }
Wink Savillef4c4d362009-04-02 01:37:03 -07003099 closeResponse;
3100
3101 return 0;
3102}
3103
Wink Savillea592eeb2009-05-22 13:26:36 -07003104static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3105 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3106 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
Wink Savillef4c4d362009-04-02 01:37:03 -07003107
Wink Savillea592eeb2009-05-22 13:26:36 -07003108 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3109 p.writeInt32(num);
Wink Savillef4c4d362009-04-02 01:37:03 -07003110
3111 startResponse;
Wink Savillea592eeb2009-05-22 13:26:36 -07003112 for (int i = 0 ; i < num ; i++ ) {
3113 p.writeInt32(p_cur[i]->service_category);
3114 p.writeInt32(p_cur[i]->language);
3115 p.writeInt32(p_cur[i]->selected);
Wink Savillef4c4d362009-04-02 01:37:03 -07003116
Wink Savillea592eeb2009-05-22 13:26:36 -07003117 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3118 selected =%d], ",
3119 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3120 p_cur[i]->selected);
Wink Savillef5903df2009-04-24 11:54:14 -07003121 }
Wink Savillea592eeb2009-05-22 13:26:36 -07003122 closeResponse;
Wink Savillef5903df2009-04-24 11:54:14 -07003123
Wink Savillef4c4d362009-04-02 01:37:03 -07003124 return 0;
3125}
3126
3127static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3128 int num;
3129 int digitCount;
3130 int digitLimit;
3131 uint8_t uct;
3132 void* dest;
3133
Wink Saville8eb2a122012-11-19 16:05:13 -08003134 RLOGD("Inside responseCdmaSms");
Wink Savillef5903df2009-04-24 11:54:14 -07003135
Wink Savillef4c4d362009-04-02 01:37:03 -07003136 if (response == NULL && responselen != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003137 RLOGE("invalid response: NULL");
Wink Savillef4c4d362009-04-02 01:37:03 -07003138 return RIL_ERRNO_INVALID_RESPONSE;
3139 }
3140
Wink Savillef5903df2009-04-24 11:54:14 -07003141 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003142 RLOGE("invalid response length was %d expected %d",
Wink Savillef5903df2009-04-24 11:54:14 -07003143 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
Wink Savillef4c4d362009-04-02 01:37:03 -07003144 return RIL_ERRNO_INVALID_RESPONSE;
3145 }
3146
3147 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3148 p.writeInt32(p_cur->uTeleserviceID);
3149 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3150 p.writeInt32(p_cur->uServicecategory);
3151 p.writeInt32(p_cur->sAddress.digit_mode);
3152 p.writeInt32(p_cur->sAddress.number_mode);
3153 p.writeInt32(p_cur->sAddress.number_type);
3154 p.writeInt32(p_cur->sAddress.number_plan);
3155 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3156 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3157 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3158 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3159 }
3160
3161 p.writeInt32(p_cur->sSubAddress.subaddressType);
3162 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3163 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3164 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3165 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3166 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3167 }
3168
3169 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3170 p.writeInt32(p_cur->uBearerDataLen);
3171 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3172 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3173 }
3174
3175 startResponse;
3176 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
Wink Saville1b5fd232009-04-22 14:50:00 -07003177 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
Wink Savillef4c4d362009-04-02 01:37:03 -07003178 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3179 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3180 closeResponse;
3181
3182 return 0;
3183}
3184
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003185/**
3186 * A write on the wakeup fd is done just to pop us out of select()
3187 * We empty the buffer here and then ril_event will reset the timers on the
3188 * way back down
3189 */
Wink Savillef4c4d362009-04-02 01:37:03 -07003190static void processWakeupCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003191 char buff[16];
3192 int ret;
3193
Wink Saville8eb2a122012-11-19 16:05:13 -08003194 RLOGV("processWakeupCallback");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003195
3196 /* empty our wakeup socket out */
3197 do {
3198 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
Wink Saville7f856802009-06-09 10:23:37 -07003199 } while (ret > 0 || (ret < 0 && errno == EINTR));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003200}
3201
Etan Cohend3652192014-06-20 08:28:44 -07003202static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003203 int ret;
3204 RequestInfo *p_cur;
Etan Cohend3652192014-06-20 08:28:44 -07003205 /* Hook for current context
3206 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3207 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3208 /* pendingRequestsHook refer to &s_pendingRequests */
3209 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003210
Etan Cohend3652192014-06-20 08:28:44 -07003211#if (SIM_COUNT >= 2)
3212 if (socket_id == RIL_SOCKET_2) {
3213 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3214 pendingRequestsHook = &s_pendingRequests_socket2;
3215 }
3216#if (SIM_COUNT >= 3)
3217 else if (socket_id == RIL_SOCKET_3) {
3218 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3219 pendingRequestsHook = &s_pendingRequests_socket3;
3220 }
3221#endif
3222#if (SIM_COUNT >= 4)
3223 else if (socket_id == RIL_SOCKET_4) {
3224 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3225 pendingRequestsHook = &s_pendingRequests_socket4;
3226 }
3227#endif
3228#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003229 /* mark pending requests as "cancelled" so we dont report responses */
Etan Cohend3652192014-06-20 08:28:44 -07003230 ret = pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003231 assert (ret == 0);
3232
Etan Cohend3652192014-06-20 08:28:44 -07003233 p_cur = *pendingRequestsHook;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003234
Etan Cohend3652192014-06-20 08:28:44 -07003235 for (p_cur = *pendingRequestsHook
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003236 ; p_cur != NULL
3237 ; p_cur = p_cur->p_next
3238 ) {
3239 p_cur->cancelled = 1;
3240 }
3241
Etan Cohend3652192014-06-20 08:28:44 -07003242 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003243 assert (ret == 0);
3244}
3245
Wink Savillef4c4d362009-04-02 01:37:03 -07003246static void processCommandsCallback(int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003247 RecordStream *p_rs;
3248 void *p_record;
3249 size_t recordlen;
3250 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003251 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003252
Etan Cohend3652192014-06-20 08:28:44 -07003253 assert(fd == p_info->fdCommand);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003254
Etan Cohend3652192014-06-20 08:28:44 -07003255 p_rs = p_info->p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003256
3257 for (;;) {
3258 /* loop until EAGAIN/EINTR, end of stream, or other error */
3259 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3260
3261 if (ret == 0 && p_record == NULL) {
3262 /* end-of-stream */
3263 break;
3264 } else if (ret < 0) {
3265 break;
3266 } else if (ret == 0) { /* && p_record != NULL */
Etan Cohend3652192014-06-20 08:28:44 -07003267 processCommandBuffer(p_record, recordlen, p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003268 }
3269 }
3270
3271 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3272 /* fatal error or end-of-stream */
3273 if (ret != 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003274 RLOGE("error on reading command socket errno:%d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003275 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003276 RLOGW("EOS. Closing command socket.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003277 }
Wink Saville7f856802009-06-09 10:23:37 -07003278
Etan Cohend3652192014-06-20 08:28:44 -07003279 close(fd);
3280 p_info->fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003281
Etan Cohend3652192014-06-20 08:28:44 -07003282 ril_event_del(p_info->commands_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003283
3284 record_stream_free(p_rs);
3285
3286 /* start listening for new connections again */
3287 rilEventAddWakeup(&s_listen_event);
3288
Etan Cohend3652192014-06-20 08:28:44 -07003289 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003290 }
3291}
3292
3293
Etan Cohend3652192014-06-20 08:28:44 -07003294static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Wink Saville5b9df332011-04-06 16:24:21 -07003295 // Inform we are connected and the ril version
Jake Hambya9c18d12011-04-12 23:32:08 -07003296 int rilVer = s_callbacks.version;
Etan Cohend3652192014-06-20 08:28:44 -07003297 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3298 &rilVer, sizeof(rilVer), socket_id);
Wink Saville5b9df332011-04-06 16:24:21 -07003299
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003300 // implicit radio state changed
Etan Cohend3652192014-06-20 08:28:44 -07003301 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3302 NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003303
3304 // Send last NITZ time data, in case it was missed
3305 if (s_lastNITZTimeData != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003306 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003307
3308 free(s_lastNITZTimeData);
3309 s_lastNITZTimeData = NULL;
3310 }
3311
3312 // Get version string
3313 if (s_callbacks.getVersion != NULL) {
3314 const char *version;
3315 version = s_callbacks.getVersion();
Wink Saville8eb2a122012-11-19 16:05:13 -08003316 RLOGI("RIL Daemon version: %s\n", version);
Wink Saville7f856802009-06-09 10:23:37 -07003317
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003318 property_set(PROPERTY_RIL_IMPL, version);
3319 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003320 RLOGI("RIL Daemon version: unavailable\n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003321 property_set(PROPERTY_RIL_IMPL, "unavailable");
3322 }
3323
3324}
3325
Wink Savillef4c4d362009-04-02 01:37:03 -07003326static void listenCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003327 int ret;
3328 int err;
3329 int is_phone_socket;
Etan Cohend3652192014-06-20 08:28:44 -07003330 int fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003331 RecordStream *p_rs;
Etan Cohend3652192014-06-20 08:28:44 -07003332 SocketListenParam *p_info = (SocketListenParam *)param;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003333
3334 struct sockaddr_un peeraddr;
3335 socklen_t socklen = sizeof (peeraddr);
3336
3337 struct ucred creds;
3338 socklen_t szCreds = sizeof(creds);
3339
3340 struct passwd *pwd = NULL;
3341
Etan Cohend3652192014-06-20 08:28:44 -07003342 assert (*p_info->fdCommand < 0);
3343 assert (fd == *p_info->fdListen);
Wink Saville7f856802009-06-09 10:23:37 -07003344
Etan Cohend3652192014-06-20 08:28:44 -07003345 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003346
Etan Cohend3652192014-06-20 08:28:44 -07003347 if (fdCommand < 0 ) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003348 RLOGE("Error on accept() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003349 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003350 rilEventAddWakeup(p_info->listen_event);
3351 return;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003352 }
3353
3354 /* check the credential of the other side and only accept socket from
3355 * phone process
Wink Saville7f856802009-06-09 10:23:37 -07003356 */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003357 errno = 0;
3358 is_phone_socket = 0;
Wink Savillef4c4d362009-04-02 01:37:03 -07003359
Etan Cohend3652192014-06-20 08:28:44 -07003360 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Wink Savillef4c4d362009-04-02 01:37:03 -07003361
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003362 if (err == 0 && szCreds > 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003363 errno = 0;
3364 pwd = getpwuid(creds.uid);
3365 if (pwd != NULL) {
Etan Cohend3652192014-06-20 08:28:44 -07003366 if (strcmp(pwd->pw_name, p_info->processName) == 0) {
Wink Savillef4c4d362009-04-02 01:37:03 -07003367 is_phone_socket = 1;
3368 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003369 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Wink Savillef4c4d362009-04-02 01:37:03 -07003370 }
3371 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003372 RLOGE("Error on getpwuid() errno: %d", errno);
Wink Savillef4c4d362009-04-02 01:37:03 -07003373 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003374 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08003375 RLOGD("Error on getsockopt() errno: %d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003376 }
3377
Etan Cohend3652192014-06-20 08:28:44 -07003378 if (!is_phone_socket) {
3379 RLOGE("RILD must accept socket from %s", p_info->processName);
Wink Saville7f856802009-06-09 10:23:37 -07003380
Etan Cohend3652192014-06-20 08:28:44 -07003381 close(fdCommand);
3382 fdCommand = -1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003383
Etan Cohend3652192014-06-20 08:28:44 -07003384 onCommandsSocketClosed(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003385
3386 /* start listening for new connections again */
Etan Cohend3652192014-06-20 08:28:44 -07003387 rilEventAddWakeup(p_info->listen_event);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003388
3389 return;
3390 }
3391
Etan Cohend3652192014-06-20 08:28:44 -07003392 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003393
3394 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003395 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003396 }
3397
Etan Cohend3652192014-06-20 08:28:44 -07003398 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003399
Etan Cohend3652192014-06-20 08:28:44 -07003400 p_info->fdCommand = fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003401
Etan Cohend3652192014-06-20 08:28:44 -07003402 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003403
Etan Cohend3652192014-06-20 08:28:44 -07003404 p_info->p_rs = p_rs;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003405
Etan Cohend3652192014-06-20 08:28:44 -07003406 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
3407 p_info->processCommandsCallback, p_info);
3408
3409 rilEventAddWakeup (p_info->commands_event);
3410
3411 onNewCommandConnect(p_info->socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003412}
3413
3414static void freeDebugCallbackArgs(int number, char **args) {
3415 for (int i = 0; i < number; i++) {
3416 if (args[i] != NULL) {
3417 free(args[i]);
3418 }
3419 }
3420 free(args);
3421}
3422
Wink Savillef4c4d362009-04-02 01:37:03 -07003423static void debugCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003424 int acceptFD, option;
3425 struct sockaddr_un peeraddr;
3426 socklen_t socklen = sizeof (peeraddr);
3427 int data;
3428 unsigned int qxdm_data[6];
3429 const char *deactData[1] = {"1"};
3430 char *actData[1];
3431 RIL_Dial dialData;
3432 int hangupData[1] = {1};
3433 int number;
3434 char **args;
Etan Cohend3652192014-06-20 08:28:44 -07003435 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
3436 int sim_id = 0;
3437
3438 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003439
3440 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
3441
3442 if (acceptFD < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003443 RLOGE ("error accepting on debug port: %d\n", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003444 return;
3445 }
3446
3447 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003448 RLOGE ("error reading on socket: number of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003449 return;
3450 }
3451 args = (char **) malloc(sizeof(char*) * number);
3452
3453 for (int i = 0; i < number; i++) {
3454 int len;
3455 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003456 RLOGE ("error reading on socket: Len of Args: \n");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003457 freeDebugCallbackArgs(i, args);
3458 return;
3459 }
3460 // +1 for null-term
3461 args[i] = (char *) malloc((sizeof(char) * len) + 1);
Wink Saville7f856802009-06-09 10:23:37 -07003462 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
Wink Saville1b5fd232009-04-22 14:50:00 -07003463 != (int)sizeof(char) * len) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003464 RLOGE ("error reading on socket: Args[%d] \n", i);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003465 freeDebugCallbackArgs(i, args);
3466 return;
3467 }
3468 char * buf = args[i];
3469 buf[len] = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003470 if ((i+1) == number) {
3471 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
3472 sim_id = atoi(args[i]);
3473 switch (sim_id) {
3474 case 0:
3475 socket_id = RIL_SOCKET_1;
3476 break;
3477 #if (SIM_COUNT >= 2)
3478 case 1:
3479 socket_id = RIL_SOCKET_2;
3480 break;
3481 #endif
3482 #if (SIM_COUNT >= 3)
3483 case 2:
3484 socket_id = RIL_SOCKET_3;
3485 break;
3486 #endif
3487 #if (SIM_COUNT >= 4)
3488 case 3:
3489 socket_id = RIL_SOCKET_4;
3490 break;
3491 #endif
3492 default:
3493 socket_id = RIL_SOCKET_1;
3494 break;
3495 }
3496 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003497 }
3498
3499 switch (atoi(args[0])) {
3500 case 0:
Wink Saville8eb2a122012-11-19 16:05:13 -08003501 RLOGI ("Connection on debug port: issuing reset.");
Etan Cohend3652192014-06-20 08:28:44 -07003502 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003503 break;
3504 case 1:
Wink Saville8eb2a122012-11-19 16:05:13 -08003505 RLOGI ("Connection on debug port: issuing radio power off.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003506 data = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003507 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003508 // Close the socket
Etan Cohend3652192014-06-20 08:28:44 -07003509 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
3510 close(s_ril_param_socket.fdCommand);
3511 s_ril_param_socket.fdCommand = -1;
3512 }
3513 #if (SIM_COUNT == 2)
3514 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
3515 close(s_ril_param_socket2.fdCommand);
3516 s_ril_param_socket2.fdCommand = -1;
3517 }
3518 #endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003519 break;
3520 case 2:
Wink Saville8eb2a122012-11-19 16:05:13 -08003521 RLOGI ("Debug port: issuing unsolicited voice network change.");
Etan Cohend3652192014-06-20 08:28:44 -07003522 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003523 break;
3524 case 3:
Wink Saville8eb2a122012-11-19 16:05:13 -08003525 RLOGI ("Debug port: QXDM log enable.");
Xia Wangd855ef42010-07-27 17:26:55 -07003526 qxdm_data[0] = 65536; // head.func_tag
3527 qxdm_data[1] = 16; // head.len
3528 qxdm_data[2] = 1; // mode: 1 for 'start logging'
3529 qxdm_data[3] = 32; // log_file_size: 32megabytes
3530 qxdm_data[4] = 0; // log_mask
3531 qxdm_data[5] = 8; // log_max_fileindex
Wink Saville7f856802009-06-09 10:23:37 -07003532 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003533 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003534 break;
3535 case 4:
Wink Saville8eb2a122012-11-19 16:05:13 -08003536 RLOGI ("Debug port: QXDM log disable.");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003537 qxdm_data[0] = 65536;
3538 qxdm_data[1] = 16;
Xia Wangd855ef42010-07-27 17:26:55 -07003539 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003540 qxdm_data[3] = 32;
3541 qxdm_data[4] = 0;
Xia Wangd855ef42010-07-27 17:26:55 -07003542 qxdm_data[5] = 8;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003543 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Etan Cohend3652192014-06-20 08:28:44 -07003544 6 * sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003545 break;
3546 case 5:
Wink Saville8eb2a122012-11-19 16:05:13 -08003547 RLOGI("Debug port: Radio On");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003548 data = 1;
Etan Cohend3652192014-06-20 08:28:44 -07003549 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003550 sleep(2);
3551 // Set network selection automatic.
Etan Cohend3652192014-06-20 08:28:44 -07003552 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003553 break;
3554 case 6:
Wink Saville8eb2a122012-11-19 16:05:13 -08003555 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003556 actData[0] = args[1];
Wink Saville7f856802009-06-09 10:23:37 -07003557 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Etan Cohend3652192014-06-20 08:28:44 -07003558 sizeof(actData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003559 break;
3560 case 7:
Wink Saville8eb2a122012-11-19 16:05:13 -08003561 RLOGI("Debug port: Deactivate Data Call");
Wink Saville7f856802009-06-09 10:23:37 -07003562 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Etan Cohend3652192014-06-20 08:28:44 -07003563 sizeof(deactData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003564 break;
3565 case 8:
Wink Saville8eb2a122012-11-19 16:05:13 -08003566 RLOGI("Debug port: Dial Call");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003567 dialData.clir = 0;
3568 dialData.address = args[1];
Etan Cohend3652192014-06-20 08:28:44 -07003569 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003570 break;
3571 case 9:
Wink Saville8eb2a122012-11-19 16:05:13 -08003572 RLOGI("Debug port: Answer Call");
Etan Cohend3652192014-06-20 08:28:44 -07003573 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003574 break;
3575 case 10:
Wink Saville8eb2a122012-11-19 16:05:13 -08003576 RLOGI("Debug port: End Call");
Wink Saville7f856802009-06-09 10:23:37 -07003577 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Etan Cohend3652192014-06-20 08:28:44 -07003578 sizeof(hangupData), socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003579 break;
3580 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08003581 RLOGE ("Invalid request");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003582 break;
3583 }
3584 freeDebugCallbackArgs(number, args);
3585 close(acceptFD);
3586}
3587
3588
Wink Savillef4c4d362009-04-02 01:37:03 -07003589static void userTimerCallback (int fd, short flags, void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003590 UserCallbackInfo *p_info;
3591
3592 p_info = (UserCallbackInfo *)param;
3593
3594 p_info->p_callback(p_info->userParam);
3595
3596
3597 // FIXME generalize this...there should be a cancel mechanism
3598 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
3599 s_last_wake_timeout_info = NULL;
3600 }
3601
3602 free(p_info);
3603}
3604
3605
3606static void *
Wink Savillef4c4d362009-04-02 01:37:03 -07003607eventLoop(void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003608 int ret;
3609 int filedes[2];
3610
3611 ril_event_init();
3612
3613 pthread_mutex_lock(&s_startupMutex);
3614
3615 s_started = 1;
3616 pthread_cond_broadcast(&s_startupCond);
3617
3618 pthread_mutex_unlock(&s_startupMutex);
3619
3620 ret = pipe(filedes);
3621
3622 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003623 RLOGE("Error in pipe() errno:%d", errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003624 return NULL;
3625 }
3626
3627 s_fdWakeupRead = filedes[0];
3628 s_fdWakeupWrite = filedes[1];
3629
3630 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
3631
3632 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
3633 processWakeupCallback, NULL);
3634
3635 rilEventAddWakeup (&s_wakeupfd_event);
3636
3637 // Only returns on error
3638 ril_event_loop();
Wink Saville8eb2a122012-11-19 16:05:13 -08003639 RLOGE ("error in event_loop_base errno:%d", errno);
Kazuhiro Ondo5cdc1352011-10-14 17:50:58 -05003640 // kill self to restart on error
3641 kill(0, SIGKILL);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003642
3643 return NULL;
3644}
3645
Wink Saville7f856802009-06-09 10:23:37 -07003646extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003647RIL_startEventLoop(void) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003648 /* spin up eventLoop thread and wait for it to get started */
3649 s_started = 0;
3650 pthread_mutex_lock(&s_startupMutex);
3651
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003652 pthread_attr_t attr;
3653 pthread_attr_init(&attr);
Wink Saville7f856802009-06-09 10:23:37 -07003654 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003655
Elliott Hughesfd81e712014-01-06 12:46:02 -08003656 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
3657 if (result != 0) {
3658 RLOGE("Failed to create dispatch thread: %s", strerror(result));
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003659 goto done;
3660 }
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003661
3662 while (s_started == 0) {
3663 pthread_cond_wait(&s_startupCond, &s_startupMutex);
3664 }
3665
Elliott Hughesc0d8dc62014-01-03 15:31:42 -08003666done:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003667 pthread_mutex_unlock(&s_startupMutex);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003668}
3669
3670// Used for testing purpose only.
3671extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
3672 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3673}
3674
Etan Cohend3652192014-06-20 08:28:44 -07003675static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
3676 int fdListen = -1;
3677 int ret;
3678 char socket_name[10];
3679
3680 memset(socket_name, 0, sizeof(char)*10);
3681
3682 switch(socket_id) {
3683 case RIL_SOCKET_1:
3684 strncpy(socket_name, RIL_getRilSocketName(), 9);
3685 break;
3686 #if (SIM_COUNT >= 2)
3687 case RIL_SOCKET_2:
3688 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
3689 break;
3690 #endif
3691 #if (SIM_COUNT >= 3)
3692 case RIL_SOCKET_3:
3693 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
3694 break;
3695 #endif
3696 #if (SIM_COUNT >= 4)
3697 case RIL_SOCKET_4:
3698 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
3699 break;
3700 #endif
3701 default:
3702 RLOGE("Socket id is wrong!!");
3703 return;
3704 }
3705
3706 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
3707
3708 fdListen = android_get_control_socket(socket_name);
3709 if (fdListen < 0) {
3710 RLOGE("Failed to get socket %s", socket_name);
3711 exit(-1);
3712 }
3713
3714 ret = listen(fdListen, 4);
3715
3716 if (ret < 0) {
3717 RLOGE("Failed to listen on control socket '%d': %s",
3718 fdListen, strerror(errno));
3719 exit(-1);
3720 }
3721 socket_listen_p->fdListen = fdListen;
3722
3723 /* note: non-persistent so we can accept only one connection at a time */
3724 ril_event_set (socket_listen_p->listen_event, fdListen, false,
3725 listenCallback, socket_listen_p);
3726
3727 rilEventAddWakeup (socket_listen_p->listen_event);
3728}
3729
Wink Saville7f856802009-06-09 10:23:37 -07003730extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003731RIL_register (const RIL_RadioFunctions *callbacks) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003732 int ret;
3733 int flags;
3734
Etan Cohend3652192014-06-20 08:28:44 -07003735 RLOGI("SIM_COUNT: %d", SIM_COUNT);
3736
Wink Saville43808972011-01-13 17:39:51 -08003737 if (callbacks == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003738 RLOGE("RIL_register: RIL_RadioFunctions * null");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003739 return;
3740 }
Wink Saville43808972011-01-13 17:39:51 -08003741 if (callbacks->version < RIL_VERSION_MIN) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003742 RLOGE("RIL_register: version %d is to old, min version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003743 callbacks->version, RIL_VERSION_MIN);
3744 return;
Wink Saville3a4840b2010-04-07 13:29:58 -07003745 }
Wink Saville43808972011-01-13 17:39:51 -08003746 if (callbacks->version > RIL_VERSION) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003747 RLOGE("RIL_register: version %d is too new, max version is %d",
Wink Saville43808972011-01-13 17:39:51 -08003748 callbacks->version, RIL_VERSION);
3749 return;
3750 }
Wink Saville8eb2a122012-11-19 16:05:13 -08003751 RLOGE("RIL_register: RIL version %d", callbacks->version);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003752
3753 if (s_registerCalled > 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003754 RLOGE("RIL_register has been called more than once. "
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003755 "Subsequent call ignored");
3756 return;
3757 }
3758
3759 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
3760
Etan Cohend3652192014-06-20 08:28:44 -07003761 /* Initialize socket1 parameters */
3762 s_ril_param_socket = {
3763 RIL_SOCKET_1, /* socket_id */
3764 -1, /* fdListen */
3765 -1, /* fdCommand */
3766 PHONE_PROCESS, /* processName */
3767 &s_commands_event, /* commands_event */
3768 &s_listen_event, /* listen_event */
3769 processCommandsCallback, /* processCommandsCallback */
3770 NULL /* p_rs */
3771 };
3772
3773#if (SIM_COUNT >= 2)
3774 s_ril_param_socket2 = {
3775 RIL_SOCKET_2, /* socket_id */
3776 -1, /* fdListen */
3777 -1, /* fdCommand */
3778 PHONE_PROCESS, /* processName */
3779 &s_commands_event_socket2, /* commands_event */
3780 &s_listen_event_socket2, /* listen_event */
3781 processCommandsCallback, /* processCommandsCallback */
3782 NULL /* p_rs */
3783 };
3784#endif
3785
3786#if (SIM_COUNT >= 3)
3787 s_ril_param_socket3 = {
3788 RIL_SOCKET_3, /* socket_id */
3789 -1, /* fdListen */
3790 -1, /* fdCommand */
3791 PHONE_PROCESS, /* processName */
3792 &s_commands_event_socket3, /* commands_event */
3793 &s_listen_event_socket3, /* listen_event */
3794 processCommandsCallback, /* processCommandsCallback */
3795 NULL /* p_rs */
3796 };
3797#endif
3798
3799#if (SIM_COUNT >= 4)
3800 s_ril_param_socket4 = {
3801 RIL_SOCKET_4, /* socket_id */
3802 -1, /* fdListen */
3803 -1, /* fdCommand */
3804 PHONE_PROCESS, /* processName */
3805 &s_commands_event_socket4, /* commands_event */
3806 &s_listen_event_socket4, /* listen_event */
3807 processCommandsCallback, /* processCommandsCallback */
3808 NULL /* p_rs */
3809 };
3810#endif
3811
3812
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003813 s_registerCalled = 1;
3814
Etan Cohend3652192014-06-20 08:28:44 -07003815 RLOGI("s_registerCalled flag set, %d", s_started);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003816 // Little self-check
3817
Wink Savillef4c4d362009-04-02 01:37:03 -07003818 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003819 assert(i == s_commands[i].requestNumber);
3820 }
3821
Wink Savillef4c4d362009-04-02 01:37:03 -07003822 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Wink Saville7f856802009-06-09 10:23:37 -07003823 assert(i + RIL_UNSOL_RESPONSE_BASE
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003824 == s_unsolResponses[i].requestNumber);
3825 }
3826
3827 // New rild impl calls RIL_startEventLoop() first
3828 // old standalone impl wants it here.
3829
3830 if (s_started == 0) {
3831 RIL_startEventLoop();
3832 }
3833
Etan Cohend3652192014-06-20 08:28:44 -07003834 // start listen socket1
3835 startListen(RIL_SOCKET_1, &s_ril_param_socket);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003836
Etan Cohend3652192014-06-20 08:28:44 -07003837#if (SIM_COUNT >= 2)
3838 // start listen socket2
3839 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
3840#endif /* (SIM_COUNT == 2) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003841
Etan Cohend3652192014-06-20 08:28:44 -07003842#if (SIM_COUNT >= 3)
3843 // start listen socket3
3844 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
3845#endif /* (SIM_COUNT == 3) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003846
Etan Cohend3652192014-06-20 08:28:44 -07003847#if (SIM_COUNT >= 4)
3848 // start listen socket4
3849 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
3850#endif /* (SIM_COUNT == 4) */
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003851
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003852
3853#if 1
3854 // start debug interface socket
3855
Etan Cohend3652192014-06-20 08:28:44 -07003856 char *inst = NULL;
3857 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
3858 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
3859 }
3860
3861 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
3862 if (inst != NULL) {
3863 strncat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
3864 }
3865
3866 s_fdDebug = android_get_control_socket(rildebug);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003867 if (s_fdDebug < 0) {
Etan Cohend3652192014-06-20 08:28:44 -07003868 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003869 exit(-1);
3870 }
3871
3872 ret = listen(s_fdDebug, 4);
3873
3874 if (ret < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003875 RLOGE("Failed to listen on ril debug socket '%d': %s",
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003876 s_fdDebug, strerror(errno));
3877 exit(-1);
3878 }
3879
3880 ril_event_set (&s_debug_event, s_fdDebug, true,
3881 debugCallback, NULL);
3882
3883 rilEventAddWakeup (&s_debug_event);
3884#endif
3885
3886}
3887
3888static int
Wink Savillef4c4d362009-04-02 01:37:03 -07003889checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003890 int ret = 0;
Etan Cohend3652192014-06-20 08:28:44 -07003891 /* Hook for current context
3892 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3893 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
3894 /* pendingRequestsHook refer to &s_pendingRequests */
3895 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Wink Saville7f856802009-06-09 10:23:37 -07003896
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003897 if (pRI == NULL) {
3898 return 0;
3899 }
3900
Etan Cohend3652192014-06-20 08:28:44 -07003901#if (SIM_COUNT >= 2)
3902 if (pRI->socket_id == RIL_SOCKET_2) {
3903 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3904 pendingRequestsHook = &s_pendingRequests_socket2;
3905 }
3906#if (SIM_COUNT >= 3)
3907 if (pRI->socket_id == RIL_SOCKET_3) {
3908 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3909 pendingRequestsHook = &s_pendingRequests_socket3;
3910 }
3911#endif
3912#if (SIM_COUNT >= 4)
3913 if (pRI->socket_id == RIL_SOCKET_4) {
3914 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3915 pendingRequestsHook = &s_pendingRequests_socket4;
3916 }
3917#endif
3918#endif
3919 pthread_mutex_lock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003920
Etan Cohend3652192014-06-20 08:28:44 -07003921 for(RequestInfo **ppCur = pendingRequestsHook
Wink Saville7f856802009-06-09 10:23:37 -07003922 ; *ppCur != NULL
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003923 ; ppCur = &((*ppCur)->p_next)
3924 ) {
3925 if (pRI == *ppCur) {
3926 ret = 1;
3927
3928 *ppCur = (*ppCur)->p_next;
3929 break;
3930 }
3931 }
3932
Etan Cohend3652192014-06-20 08:28:44 -07003933 pthread_mutex_unlock(pendingRequestsMutexHook);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003934
3935 return ret;
3936}
3937
3938
3939extern "C" void
Wink Savillef4c4d362009-04-02 01:37:03 -07003940RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003941 RequestInfo *pRI;
3942 int ret;
Etan Cohend3652192014-06-20 08:28:44 -07003943 int fd = s_ril_param_socket.fdCommand;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003944 size_t errorOffset;
Etan Cohend3652192014-06-20 08:28:44 -07003945 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003946
3947 pRI = (RequestInfo *)t;
3948
Etan Cohend3652192014-06-20 08:28:44 -07003949 socket_id = pRI->socket_id;
3950#if (SIM_COUNT >= 2)
3951 if (socket_id == RIL_SOCKET_2) {
3952 fd = s_ril_param_socket2.fdCommand;
3953 }
3954#if (SIM_COUNT >= 3)
3955 if (socket_id == RIL_SOCKET_3) {
3956 fd = s_ril_param_socket3.fdCommand;
3957 }
3958#endif
3959#if (SIM_COUNT >= 4)
3960 if (socket_id == RIL_SOCKET_4) {
3961 fd = s_ril_param_socket4.fdCommand;
3962 }
3963#endif
3964#endif
3965 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
3966
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003967 if (!checkAndDequeueRequestInfo(pRI)) {
Wink Saville8eb2a122012-11-19 16:05:13 -08003968 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003969 return;
3970 }
3971
3972 if (pRI->local > 0) {
3973 // Locally issued command...void only!
3974 // response does not go back up the command socket
Wink Saville8eb2a122012-11-19 16:05:13 -08003975 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003976
3977 goto done;
3978 }
3979
3980 appendPrintBuf("[%04d]< %s",
3981 pRI->token, requestToString(pRI->pCI->requestNumber));
3982
3983 if (pRI->cancelled == 0) {
3984 Parcel p;
3985
3986 p.writeInt32 (RESPONSE_SOLICITED);
3987 p.writeInt32 (pRI->token);
3988 errorOffset = p.dataPosition();
3989
3990 p.writeInt32 (e);
3991
johnwangb2a61842009-06-02 14:55:45 -07003992 if (response != NULL) {
3993 // there is a response payload, no matter success or not.
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003994 ret = pRI->pCI->responseFunction(p, response, responselen);
3995
3996 /* if an error occurred, rewind and mark it */
3997 if (ret != 0) {
Etan Cohend3652192014-06-20 08:28:44 -07003998 RLOGE ("responseFunction error, ret %d", ret);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08003999 p.setDataPosition(errorOffset);
4000 p.writeInt32 (ret);
4001 }
johnwangb2a61842009-06-02 14:55:45 -07004002 }
4003
4004 if (e != RIL_E_SUCCESS) {
4005 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004006 }
4007
Etan Cohend3652192014-06-20 08:28:44 -07004008 if (fd < 0) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004009 RLOGD ("RIL onRequestComplete: Command channel closed");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004010 }
Etan Cohend3652192014-06-20 08:28:44 -07004011 sendResponse(p, socket_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004012 }
4013
4014done:
4015 free(pRI);
4016}
4017
4018
4019static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004020grabPartialWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004021 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4022}
4023
4024static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004025releaseWakeLock() {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004026 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4027}
4028
4029/**
4030 * Timer callback to put us back to sleep before the default timeout
4031 */
4032static void
Wink Savillef4c4d362009-04-02 01:37:03 -07004033wakeTimeoutCallback (void *param) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004034 // We're using "param != NULL" as a cancellation mechanism
4035 if (param == NULL) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004036 //RLOGD("wakeTimeout: releasing wake lock");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004037
4038 releaseWakeLock();
4039 } else {
Wink Saville8eb2a122012-11-19 16:05:13 -08004040 //RLOGD("wakeTimeout: releasing wake lock CANCELLED");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004041 }
4042}
4043
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004044static int
4045decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4046 switch (radioState) {
4047 case RADIO_STATE_SIM_NOT_READY:
4048 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4049 case RADIO_STATE_SIM_READY:
4050 return RADIO_TECH_UMTS;
4051
4052 case RADIO_STATE_RUIM_NOT_READY:
4053 case RADIO_STATE_RUIM_READY:
4054 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4055 case RADIO_STATE_NV_NOT_READY:
4056 case RADIO_STATE_NV_READY:
4057 return RADIO_TECH_1xRTT;
4058
4059 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004060 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004061 return -1;
4062 }
4063}
4064
4065static int
4066decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4067 switch (radioState) {
4068 case RADIO_STATE_SIM_NOT_READY:
4069 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4070 case RADIO_STATE_SIM_READY:
4071 case RADIO_STATE_RUIM_NOT_READY:
4072 case RADIO_STATE_RUIM_READY:
4073 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4074 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4075
4076 case RADIO_STATE_NV_NOT_READY:
4077 case RADIO_STATE_NV_READY:
4078 return CDMA_SUBSCRIPTION_SOURCE_NV;
4079
4080 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004081 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004082 return -1;
4083 }
4084}
4085
4086static int
4087decodeSimStatus (RIL_RadioState radioState) {
4088 switch (radioState) {
4089 case RADIO_STATE_SIM_NOT_READY:
4090 case RADIO_STATE_RUIM_NOT_READY:
4091 case RADIO_STATE_NV_NOT_READY:
4092 case RADIO_STATE_NV_READY:
4093 return -1;
4094 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4095 case RADIO_STATE_SIM_READY:
4096 case RADIO_STATE_RUIM_READY:
4097 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4098 return radioState;
4099 default:
Wink Saville8eb2a122012-11-19 16:05:13 -08004100 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004101 return -1;
4102 }
4103}
4104
4105static bool is3gpp2(int radioTech) {
4106 switch (radioTech) {
4107 case RADIO_TECH_IS95A:
4108 case RADIO_TECH_IS95B:
4109 case RADIO_TECH_1xRTT:
4110 case RADIO_TECH_EVDO_0:
4111 case RADIO_TECH_EVDO_A:
4112 case RADIO_TECH_EVDO_B:
4113 case RADIO_TECH_EHRPD:
4114 return true;
4115 default:
4116 return false;
4117 }
4118}
4119
4120/* If RIL sends SIM states or RUIM states, store the voice radio
4121 * technology and subscription source information so that they can be
4122 * returned when telephony framework requests them
4123 */
4124static RIL_RadioState
Etan Cohend3652192014-06-20 08:28:44 -07004125processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004126
4127 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4128 int newVoiceRadioTech;
4129 int newCdmaSubscriptionSource;
4130 int newSimStatus;
4131
4132 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4133 from Radio State and send change notifications if there has been a change */
4134 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4135 if(newVoiceRadioTech != voiceRadioTech) {
4136 voiceRadioTech = newVoiceRadioTech;
Etan Cohend3652192014-06-20 08:28:44 -07004137 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4138 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004139 }
4140 if(is3gpp2(newVoiceRadioTech)) {
4141 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4142 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4143 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Etan Cohend3652192014-06-20 08:28:44 -07004144 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4145 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004146 }
4147 }
4148 newSimStatus = decodeSimStatus(newRadioState);
4149 if(newSimStatus != simRuimStatus) {
4150 simRuimStatus = newSimStatus;
Etan Cohend3652192014-06-20 08:28:44 -07004151 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004152 }
4153
4154 /* Send RADIO_ON to telephony */
4155 newRadioState = RADIO_STATE_ON;
4156 }
4157
4158 return newRadioState;
4159}
4160
Etan Cohend3652192014-06-20 08:28:44 -07004161
4162#if defined(ANDROID_MULTI_SIM)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004163extern "C"
Etan Cohend3652192014-06-20 08:28:44 -07004164void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
4165 size_t datalen, RIL_SOCKET_ID socket_id)
4166#else
4167extern "C"
4168void RIL_onUnsolicitedResponse(int unsolResponse, void *data,
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004169 size_t datalen)
Etan Cohend3652192014-06-20 08:28:44 -07004170#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004171{
4172 int unsolResponseIndex;
4173 int ret;
4174 int64_t timeReceived = 0;
4175 bool shouldScheduleTimeout = false;
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004176 RIL_RadioState newState;
Etan Cohend3652192014-06-20 08:28:44 -07004177 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
4178
4179#if defined(ANDROID_MULTI_SIM)
4180 soc_id = socket_id;
4181#endif
4182
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004183
4184 if (s_registerCalled == 0) {
4185 // Ignore RIL_onUnsolicitedResponse before RIL_register
Wink Saville8eb2a122012-11-19 16:05:13 -08004186 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004187 return;
4188 }
Wink Saville7f856802009-06-09 10:23:37 -07004189
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004190 unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4191
4192 if ((unsolResponseIndex < 0)
4193 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
Wink Saville8eb2a122012-11-19 16:05:13 -08004194 RLOGE("unsupported unsolicited response code %d", unsolResponse);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004195 return;
4196 }
4197
4198 // Grab a wake lock if needed for this reponse,
4199 // as we exit we'll either release it immediately
4200 // or set a timer to release it later.
4201 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
4202 case WAKE_PARTIAL:
4203 grabPartialWakeLock();
4204 shouldScheduleTimeout = true;
4205 break;
4206
4207 case DONT_WAKE:
4208 default:
4209 // No wake lock is grabed so don't set timeout
4210 shouldScheduleTimeout = false;
4211 break;
4212 }
4213
4214 // Mark the time this was received, doing this
4215 // after grabing the wakelock incase getting
4216 // the elapsedRealTime might cause us to goto
4217 // sleep.
4218 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4219 timeReceived = elapsedRealtime();
4220 }
4221
4222 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4223
4224 Parcel p;
4225
4226 p.writeInt32 (RESPONSE_UNSOLICITED);
4227 p.writeInt32 (unsolResponse);
4228
4229 ret = s_unsolResponses[unsolResponseIndex]
Bernhard Rosenkränzer6e7c1962013-12-12 10:01:10 +01004230 .responseFunction(p, const_cast<void*>(data), datalen);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004231 if (ret != 0) {
4232 // Problem with the response. Don't continue;
4233 goto error_exit;
4234 }
4235
4236 // some things get more payload
4237 switch(unsolResponse) {
4238 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Etan Cohend3652192014-06-20 08:28:44 -07004239 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004240 p.writeInt32(newState);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004241 appendPrintBuf("%s {%s}", printBuf,
Etan Cohend3652192014-06-20 08:28:44 -07004242 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004243 break;
4244
4245
4246 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4247 // Store the time that this was received so the
4248 // handler of this message can account for
4249 // the time it takes to arrive and process. In
4250 // particular the system has been known to sleep
4251 // before this message can be processed.
4252 p.writeInt64(timeReceived);
4253 break;
4254 }
4255
Etan Cohend3652192014-06-20 08:28:44 -07004256 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
4257 ret = sendResponse(p, soc_id);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004258 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4259
4260 // Unfortunately, NITZ time is not poll/update like everything
4261 // else in the system. So, if the upstream client isn't connected,
4262 // keep a copy of the last NITZ response (with receive time noted
4263 // above) around so we can deliver it when it is connected
4264
4265 if (s_lastNITZTimeData != NULL) {
4266 free (s_lastNITZTimeData);
4267 s_lastNITZTimeData = NULL;
4268 }
4269
4270 s_lastNITZTimeData = malloc(p.dataSize());
4271 s_lastNITZTimeDataSize = p.dataSize();
4272 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
4273 }
4274
4275 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
4276 // FIXME The java code should handshake here to release wake lock
4277
4278 if (shouldScheduleTimeout) {
4279 // Cancel the previous request
4280 if (s_last_wake_timeout_info != NULL) {
4281 s_last_wake_timeout_info->userParam = (void *)1;
4282 }
4283
4284 s_last_wake_timeout_info
4285 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
4286 &TIMEVAL_WAKE_TIMEOUT);
4287 }
4288
4289 // Normal exit
4290 return;
4291
4292error_exit:
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004293 if (shouldScheduleTimeout) {
4294 releaseWakeLock();
4295 }
4296}
4297
Wink Saville7f856802009-06-09 10:23:37 -07004298/** FIXME generalize this if you track UserCAllbackInfo, clear it
4299 when the callback occurs
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004300*/
4301static UserCallbackInfo *
Wink Saville7f856802009-06-09 10:23:37 -07004302internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004303 const struct timeval *relativeTime)
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004304{
4305 struct timeval myRelativeTime;
4306 UserCallbackInfo *p_info;
4307
4308 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
4309
Wink Saville7f856802009-06-09 10:23:37 -07004310 p_info->p_callback = callback;
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004311 p_info->userParam = param;
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004312
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004313 if (relativeTime == NULL) {
4314 /* treat null parameter as a 0 relative time */
4315 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
4316 } else {
4317 /* FIXME I think event_add's tv param is really const anyway */
4318 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
4319 }
4320
4321 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
4322
4323 ril_timer_add(&(p_info->event), &myRelativeTime);
4324
4325 triggerEvLoop();
4326 return p_info;
4327}
4328
Naveen Kalla7edd07c2010-06-21 18:54:47 -07004329
4330extern "C" void
Dianne Hackborn0d9f0c02010-06-25 16:50:46 -07004331RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
4332 const struct timeval *relativeTime) {
4333 internalRequestTimedCallback (callback, param, relativeTime);
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004334}
4335
4336const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004337failCauseToString(RIL_Errno e) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004338 switch(e) {
4339 case RIL_E_SUCCESS: return "E_SUCCESS";
Robert Greenwalt2126ab22013-04-09 12:20:45 -07004340 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004341 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
4342 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
4343 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
4344 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
4345 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
4346 case RIL_E_CANCELLED: return "E_CANCELLED";
4347 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
4348 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
4349 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004350 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
John Wang75534472010-04-20 15:11:42 -07004351 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
Wink Saville7f856802009-06-09 10:23:37 -07004352#ifdef FEATURE_MULTIMODE_ANDROID
Wink Savillef4c4d362009-04-02 01:37:03 -07004353 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
4354 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
4355#endif
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004356 default: return "<unknown error>";
4357 }
4358}
4359
4360const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004361radioStateToString(RIL_RadioState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004362 switch(s) {
4363 case RADIO_STATE_OFF: return "RADIO_OFF";
4364 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
4365 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
4366 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
4367 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004368 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
4369 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
4370 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
4371 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
4372 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004373 case RADIO_STATE_ON:return"RADIO_ON";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004374 default: return "<unknown state>";
4375 }
4376}
4377
4378const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004379callStateToString(RIL_CallState s) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004380 switch(s) {
4381 case RIL_CALL_ACTIVE : return "ACTIVE";
4382 case RIL_CALL_HOLDING: return "HOLDING";
4383 case RIL_CALL_DIALING: return "DIALING";
4384 case RIL_CALL_ALERTING: return "ALERTING";
4385 case RIL_CALL_INCOMING: return "INCOMING";
4386 case RIL_CALL_WAITING: return "WAITING";
4387 default: return "<unknown state>";
4388 }
4389}
4390
4391const char *
Wink Savillef4c4d362009-04-02 01:37:03 -07004392requestToString(int request) {
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004393/*
4394 cat libs/telephony/ril_commands.h \
4395 | egrep "^ *{RIL_" \
4396 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
4397
4398
4399 cat libs/telephony/ril_unsol_commands.h \
4400 | egrep "^ *{RIL_" \
4401 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
4402
4403*/
4404 switch(request) {
4405 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
4406 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
4407 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
4408 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
4409 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
4410 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
4411 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
4412 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
4413 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
4414 case RIL_REQUEST_DIAL: return "DIAL";
4415 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
4416 case RIL_REQUEST_HANGUP: return "HANGUP";
4417 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
4418 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
4419 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
4420 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
4421 case RIL_REQUEST_UDUB: return "UDUB";
4422 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
4423 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
Wink Savillec0114b32011-02-18 10:14:07 -08004424 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
4425 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004426 case RIL_REQUEST_OPERATOR: return "OPERATOR";
4427 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
4428 case RIL_REQUEST_DTMF: return "DTMF";
4429 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
4430 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004431 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004432 case RIL_REQUEST_SIM_IO: return "SIM_IO";
4433 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
4434 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
4435 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
4436 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
4437 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
4438 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
4439 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
4440 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
4441 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
4442 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
4443 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
4444 case RIL_REQUEST_ANSWER: return "ANSWER";
Wink Savillef4c4d362009-04-02 01:37:03 -07004445 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004446 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
4447 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
4448 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
4449 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
4450 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
4451 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
4452 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
4453 case RIL_REQUEST_DTMF_START: return "DTMF_START";
4454 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
4455 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
4456 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
4457 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
4458 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
4459 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
4460 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
4461 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
4462 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
Wink Savillef4c4d362009-04-02 01:37:03 -07004463 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
4464 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004465 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
4466 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
4467 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
Wink Savillef4c4d362009-04-02 01:37:03 -07004468 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
4469 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004470 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
4471 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
4472 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
4473 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
4474 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
4475 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
4476 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
4477 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
Wink Savillec0114b32011-02-18 10:14:07 -08004478 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Wink Savillef4c4d362009-04-02 01:37:03 -07004479 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
4480 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
4481 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
4482 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
4483 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
4484 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
4485 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
4486 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
4487 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
4488 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
Wink Savillea592eeb2009-05-22 13:26:36 -07004489 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
4490 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
4491 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
4492 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
4493 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Naveen Kalla03c1edf2009-09-23 11:18:35 -07004494 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Wink Savillef4c4d362009-04-02 01:37:03 -07004495 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
4496 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
4497 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
4498 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
jsh000a9fe2009-05-11 14:52:35 -07004499 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
4500 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
4501 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
jsh09a68ba2009-06-10 11:56:38 -07004502 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
jsh563fd722010-06-08 16:52:24 -07004503 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
Wink Savillec0114b32011-02-18 10:14:07 -08004504 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
Jake Hambyfa8d5842011-08-19 16:22:18 -07004505 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
Jake Hamby300105d2011-09-26 01:01:44 -07004506 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
4507 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004508 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
Wink Saville8a9e0212013-04-09 12:11:38 -07004509 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
4510 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Sungmin Choi75697532013-04-26 15:04:45 -07004511 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004512 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
4513 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Shishir Agrawal2458d8d2013-11-27 14:53:05 -08004514 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
4515 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
4516 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
4517 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Etan Cohend3652192014-06-20 08:28:44 -07004518 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
4519 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
4520 case RIL_REQUEST_GET_HARDWARE_CONFIG: return"GET_HARDWARE_CONFIG";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004521 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
4522 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004523 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004524 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
4525 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
4526 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
4527 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
4528 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
4529 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
4530 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
4531 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
4532 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
4533 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
4534 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
4535 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
4536 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Wink Savillef4c4d362009-04-02 01:37:03 -07004537 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004538 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
Wink Savillef4c4d362009-04-02 01:37:03 -07004539 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
4540 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
4541 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
4542 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
Wink Saville3d54e742009-05-18 18:00:44 -07004543 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
4544 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
4545 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
4546 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
4547 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
Jaikumar Ganeshaf6ecbf2009-04-29 13:27:51 -07004548 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
John Wang5d621da2009-09-18 17:17:48 -07004549 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
John Wang5909cf82010-01-29 00:18:54 -08004550 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
Wink Savilleee274582011-04-16 15:05:49 -07004551 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
Wink Savillec0114b32011-02-18 10:14:07 -08004552 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
4553 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
Wink Saville5b9df332011-04-06 16:24:21 -07004554 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
Naveen Kalla2bc78d62011-12-07 16:22:53 -08004555 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Wink Saville8a9e0212013-04-09 12:11:38 -07004556 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Sukanya Rajkhowaa18b9d12013-09-10 12:30:13 -07004557 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Etan Cohend3652192014-06-20 08:28:44 -07004558 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
4559 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
4560 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004561 default: return "<unknown request>";
4562 }
4563}
4564
Etan Cohend3652192014-06-20 08:28:44 -07004565const char *
4566rilSocketIdToString(RIL_SOCKET_ID socket_id)
4567{
4568 switch(socket_id) {
4569 case RIL_SOCKET_1:
4570 return "RIL_SOCKET_1";
4571#if (SIM_COUNT >= 2)
4572 case RIL_SOCKET_2:
4573 return "RIL_SOCKET_2";
4574#endif
4575#if (SIM_COUNT >= 3)
4576 case RIL_SOCKET_3:
4577 return "RIL_SOCKET_3";
4578#endif
4579#if (SIM_COUNT >= 4)
4580 case RIL_SOCKET_4:
4581 return "RIL_SOCKET_4";
4582#endif
4583 default:
4584 return "not a valid RIL";
4585 }
4586}
4587
The Android Open Source Project00f06fc2009-03-03 19:32:15 -08004588} /* namespace android */