blob: e2a1c8bd17fcbaeef486eff87be3be3ab3690d46 [file] [log] [blame]
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001/* //device/libs/telephony/ril.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** 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
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** 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
15** limitations under the License.
16*/
17
18#define LOG_TAG "RILC"
19
20#include <hardware_legacy/power.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020021#include <telephony/ril.h>
22#include <telephony/ril_cdma_sms.h>
23#include <cutils/sockets.h>
24#include <cutils/jstring.h>
Andrew Jiangca4a9a02014-01-18 18:04:08 -050025#include <telephony/record_stream.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020026#include <utils/Log.h>
27#include <utils/SystemClock.h>
28#include <pthread.h>
29#include <binder/Parcel.h>
30#include <cutils/jstring.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020031#include <sys/types.h>
XpLoDWilDba5c6a32013-07-27 21:12:19 +020032#include <sys/limits.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020033#include <pwd.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020034#include <stdio.h>
35#include <stdlib.h>
36#include <stdarg.h>
37#include <string.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <time.h>
41#include <errno.h>
42#include <assert.h>
43#include <ctype.h>
44#include <alloca.h>
45#include <sys/un.h>
46#include <assert.h>
47#include <netinet/in.h>
48#include <cutils/properties.h>
Dheeraj Shettycc231012014-07-02 21:27:57 +020049#include <RilSapSocket.h>
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020050
Dheeraj Shettycc231012014-07-02 21:27:57 +020051extern "C" void
52RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020053namespace android {
54
55#define PHONE_PROCESS "radio"
Dheeraj Shettycc231012014-07-02 21:27:57 +020056#define BLUETOOTH_PROCESS "bluetooth"
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020057
58#define SOCKET_NAME_RIL "rild"
Howard Sue32dbfd2015-01-07 15:55:57 +080059#define SOCKET2_NAME_RIL "rild2"
60#define SOCKET3_NAME_RIL "rild3"
61#define SOCKET4_NAME_RIL "rild4"
62
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020063#define SOCKET_NAME_RIL_DEBUG "rild-debug"
64
65#define ANDROID_WAKE_LOCK_NAME "radio-interface"
66
Nathan Haroldd6306fa2015-07-28 14:54:58 -070067#define ANDROID_WAKE_LOCK_SECS 0
68#define ANDROID_WAKE_LOCK_USECS 200000
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020069
70#define PROPERTY_RIL_IMPL "gsm.version.ril-impl"
71
72// match with constant in RIL.java
73#define MAX_COMMAND_BYTES (8 * 1024)
74
75// Basically: memset buffers that the client library
76// shouldn't be using anymore in an attempt to find
77// memory usage issues sooner.
78#define MEMSET_FREED 1
79
80#define NUM_ELEMS(a) (sizeof (a) / sizeof (a)[0])
81
82#define MIN(a,b) ((a)<(b) ? (a) : (b))
83
84/* Constants for response types */
85#define RESPONSE_SOLICITED 0
86#define RESPONSE_UNSOLICITED 1
87
88/* Negative values for private RIL errno's */
89#define RIL_ERRNO_INVALID_RESPONSE -1
90
91// request, response, and unsolicited msg print macro
92#define PRINTBUF_SIZE 8096
93
Robert Greenwaltbc29c432015-04-29 16:57:39 -070094// Enable verbose logging
95#define VDBG 0
96
Daniel Hillenbrand601dc852013-07-07 10:06:59 +020097// Enable RILC log
98#define RILC_LOG 0
99
100#if RILC_LOG
101 #define startRequest sprintf(printBuf, "(")
102 #define closeRequest sprintf(printBuf, "%s)", printBuf)
103 #define printRequest(token, req) \
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200104 RLOGD("[%04d]> %s %s", token, requestToString(req), printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200105
106 #define startResponse sprintf(printBuf, "%s {", printBuf)
107 #define closeResponse sprintf(printBuf, "%s}", printBuf)
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200108 #define printResponse RLOGD("%s", printBuf)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200109
110 #define clearPrintBuf printBuf[0] = 0
111 #define removeLastChar printBuf[strlen(printBuf)-1] = 0
112 #define appendPrintBuf(x...) sprintf(printBuf, x)
113#else
114 #define startRequest
115 #define closeRequest
116 #define printRequest(token, req)
117 #define startResponse
118 #define closeResponse
119 #define printResponse
120 #define clearPrintBuf
121 #define removeLastChar
122 #define appendPrintBuf(x...)
123#endif
124
125enum WakeType {DONT_WAKE, WAKE_PARTIAL};
126
127typedef struct {
128 int requestNumber;
129 void (*dispatchFunction) (Parcel &p, struct RequestInfo *pRI);
130 int(*responseFunction) (Parcel &p, void *response, size_t responselen);
131} CommandInfo;
132
133typedef struct {
134 int requestNumber;
135 int (*responseFunction) (Parcel &p, void *response, size_t responselen);
136 WakeType wakeType;
137} UnsolResponseInfo;
138
139typedef struct RequestInfo {
140 int32_t token; //this is not RIL_Token
141 CommandInfo *pCI;
142 struct RequestInfo *p_next;
143 char cancelled;
144 char local; // responses to local commands do not go back to command process
Howard Sue32dbfd2015-01-07 15:55:57 +0800145 RIL_SOCKET_ID socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200146} RequestInfo;
147
148typedef struct UserCallbackInfo {
149 RIL_TimedCallback p_callback;
150 void *userParam;
151 struct ril_event event;
152 struct UserCallbackInfo *p_next;
153} UserCallbackInfo;
154
Howard Sue32dbfd2015-01-07 15:55:57 +0800155extern "C" const char * requestToString(int request);
156extern "C" const char * failCauseToString(RIL_Errno);
157extern "C" const char * callStateToString(RIL_CallState);
158extern "C" const char * radioStateToString(RIL_RadioState);
159extern "C" const char * rilSocketIdToString(RIL_SOCKET_ID socket_id);
160
161extern "C"
162char rild[MAX_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200163
Howard Subd82ef12015-04-12 10:25:05 +0200164#define RIL_VENDOR_COMMANDS_OFFSET 10000
165
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200166/*******************************************************************/
167
168RIL_RadioFunctions s_callbacks = {0, NULL, NULL, NULL, NULL, NULL};
169static int s_registerCalled = 0;
170
171static pthread_t s_tid_dispatch;
172static pthread_t s_tid_reader;
173static int s_started = 0;
174
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200175static int s_fdDebug = -1;
Howard Sue32dbfd2015-01-07 15:55:57 +0800176static int s_fdDebug_socket2 = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200177
178static int s_fdWakeupRead;
179static int s_fdWakeupWrite;
180
181static struct ril_event s_commands_event;
182static struct ril_event s_wakeupfd_event;
183static struct ril_event s_listen_event;
Howard Sue32dbfd2015-01-07 15:55:57 +0800184static SocketListenParam s_ril_param_socket;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200185
186static pthread_mutex_t s_pendingRequestsMutex = PTHREAD_MUTEX_INITIALIZER;
187static pthread_mutex_t s_writeMutex = PTHREAD_MUTEX_INITIALIZER;
Howard Sue32dbfd2015-01-07 15:55:57 +0800188static RequestInfo *s_pendingRequests = NULL;
189
190#if (SIM_COUNT >= 2)
191static struct ril_event s_commands_event_socket2;
192static struct ril_event s_listen_event_socket2;
193static SocketListenParam s_ril_param_socket2;
194
195static pthread_mutex_t s_pendingRequestsMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
196static pthread_mutex_t s_writeMutex_socket2 = PTHREAD_MUTEX_INITIALIZER;
197static RequestInfo *s_pendingRequests_socket2 = NULL;
198#endif
199
200#if (SIM_COUNT >= 3)
201static struct ril_event s_commands_event_socket3;
202static struct ril_event s_listen_event_socket3;
203static SocketListenParam s_ril_param_socket3;
204
205static pthread_mutex_t s_pendingRequestsMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
206static pthread_mutex_t s_writeMutex_socket3 = PTHREAD_MUTEX_INITIALIZER;
207static RequestInfo *s_pendingRequests_socket3 = NULL;
208#endif
209
210#if (SIM_COUNT >= 4)
211static struct ril_event s_commands_event_socket4;
212static struct ril_event s_listen_event_socket4;
213static SocketListenParam s_ril_param_socket4;
214
215static pthread_mutex_t s_pendingRequestsMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
216static pthread_mutex_t s_writeMutex_socket4 = PTHREAD_MUTEX_INITIALIZER;
217static RequestInfo *s_pendingRequests_socket4 = NULL;
218#endif
219
220static struct ril_event s_wake_timeout_event;
221static struct ril_event s_debug_event;
222
Howard Subd82ef12015-04-12 10:25:05 +0200223
Nathan Haroldd6306fa2015-07-28 14:54:58 -0700224static const struct timeval TIMEVAL_WAKE_TIMEOUT = {ANDROID_WAKE_LOCK_SECS,ANDROID_WAKE_LOCK_USECS};
Howard Sue32dbfd2015-01-07 15:55:57 +0800225
Howard Subd82ef12015-04-12 10:25:05 +0200226
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200227static pthread_mutex_t s_startupMutex = PTHREAD_MUTEX_INITIALIZER;
228static pthread_cond_t s_startupCond = PTHREAD_COND_INITIALIZER;
229
230static pthread_mutex_t s_dispatchMutex = PTHREAD_MUTEX_INITIALIZER;
231static pthread_cond_t s_dispatchCond = PTHREAD_COND_INITIALIZER;
232
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200233static RequestInfo *s_toDispatchHead = NULL;
234static RequestInfo *s_toDispatchTail = NULL;
235
236static UserCallbackInfo *s_last_wake_timeout_info = NULL;
237
238static void *s_lastNITZTimeData = NULL;
239static size_t s_lastNITZTimeDataSize;
240
241#if RILC_LOG
242 static char printBuf[PRINTBUF_SIZE];
243#endif
244
245/*******************************************************************/
Howard Sue32dbfd2015-01-07 15:55:57 +0800246static int sendResponse (Parcel &p, RIL_SOCKET_ID socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200247
248static void dispatchVoid (Parcel& p, RequestInfo *pRI);
249static void dispatchString (Parcel& p, RequestInfo *pRI);
250static void dispatchStrings (Parcel& p, RequestInfo *pRI);
251static void dispatchInts (Parcel& p, RequestInfo *pRI);
252static void dispatchDial (Parcel& p, RequestInfo *pRI);
253static void dispatchSIM_IO (Parcel& p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800254static void dispatchSIM_APDU (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200255static void dispatchCallForward(Parcel& p, RequestInfo *pRI);
256static void dispatchRaw(Parcel& p, RequestInfo *pRI);
257static void dispatchSmsWrite (Parcel &p, RequestInfo *pRI);
258static void dispatchDataCall (Parcel& p, RequestInfo *pRI);
259static void dispatchVoiceRadioTech (Parcel& p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500260static void dispatchSetInitialAttachApn (Parcel& p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200261static void dispatchCdmaSubscriptionSource (Parcel& p, RequestInfo *pRI);
262
263static void dispatchCdmaSms(Parcel &p, RequestInfo *pRI);
Andrew Jiangca4a9a02014-01-18 18:04:08 -0500264static void dispatchImsSms(Parcel &p, RequestInfo *pRI);
265static void dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
266static void dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200267static void dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI);
268static void dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI);
269static void dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI);
270static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI);
Howard Sue32dbfd2015-01-07 15:55:57 +0800271static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI);
272static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI);
273static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI);
274static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI);
275static void dispatchDataProfile(Parcel &p, RequestInfo *pRI);
Howard Subd82ef12015-04-12 10:25:05 +0200276static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200277static int responseInts(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +0200278static int responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200279static int responseStrings(Parcel &p, void *response, size_t responselen);
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +0530280static int responseStringsNetworks(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200281static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search);
282static int responseString(Parcel &p, void *response, size_t responselen);
283static int responseVoid(Parcel &p, void *response, size_t responselen);
284static int responseCallList(Parcel &p, void *response, size_t responselen);
285static int responseSMS(Parcel &p, void *response, size_t responselen);
286static int responseSIM_IO(Parcel &p, void *response, size_t responselen);
287static int responseCallForwards(Parcel &p, void *response, size_t responselen);
288static int responseDataCallList(Parcel &p, void *response, size_t responselen);
289static int responseSetupDataCall(Parcel &p, void *response, size_t responselen);
290static int responseRaw(Parcel &p, void *response, size_t responselen);
291static int responseSsn(Parcel &p, void *response, size_t responselen);
292static int responseSimStatus(Parcel &p, void *response, size_t responselen);
293static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen);
294static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen);
295static int responseCdmaSms(Parcel &p, void *response, size_t responselen);
296static int responseCellList(Parcel &p, void *response, size_t responselen);
297static int responseCdmaInformationRecords(Parcel &p,void *response, size_t responselen);
298static int responseRilSignalStrength(Parcel &p,void *response, size_t responselen);
299static int responseCallRing(Parcel &p, void *response, size_t responselen);
300static int responseCdmaSignalInfoRecord(Parcel &p,void *response, size_t responselen);
301static int responseCdmaCallWaiting(Parcel &p,void *response, size_t responselen);
302static int responseSimRefresh(Parcel &p, void *response, size_t responselen);
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200303static int responseCellInfoList(Parcel &p, void *response, size_t responselen);
Howard Sue32dbfd2015-01-07 15:55:57 +0800304static int responseHardwareConfig(Parcel &p, void *response, size_t responselen);
305static int responseDcRtInfo(Parcel &p, void *response, size_t responselen);
Howard Subd82ef12015-04-12 10:25:05 +0200306static int responseRadioCapability(Parcel &p, void *response, size_t responselen);
307static int responseSSData(Parcel &p, void *response, size_t responselen);
fenglu9bdede02015-04-14 14:53:55 -0700308static int responseLceStatus(Parcel &p, void *response, size_t responselen);
309static int responseLceData(Parcel &p, void *response, size_t responselen);
Prerepa Viswanadham8e755592015-05-28 00:37:32 -0700310static int responseActivityData(Parcel &p, void *response, size_t responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200311
312static int decodeVoiceRadioTechnology (RIL_RadioState radioState);
313static int decodeCdmaSubscriptionSource (RIL_RadioState radioState);
Howard Subd82ef12015-04-12 10:25:05 +0200314static RIL_RadioState processRadioState(RIL_RadioState newRadioState);
315
316static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200317
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200318#ifdef RIL_SHLIB
Howard Sue32dbfd2015-01-07 15:55:57 +0800319#if defined(ANDROID_MULTI_SIM)
Andreas Schneider47b2d962015-04-13 22:54:49 +0200320extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +0800321 size_t datalen, RIL_SOCKET_ID socket_id);
322#else
Andreas Schneider47b2d962015-04-13 22:54:49 +0200323extern "C" void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200324 size_t datalen);
325#endif
Howard Sue32dbfd2015-01-07 15:55:57 +0800326#endif
327
328#if defined(ANDROID_MULTI_SIM)
329#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c), (d))
330#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d), (e))
331#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest(a)
332#else
333#define RIL_UNSOL_RESPONSE(a, b, c, d) RIL_onUnsolicitedResponse((a), (b), (c))
334#define CALL_ONREQUEST(a, b, c, d, e) s_callbacks.onRequest((a), (b), (c), (d))
335#define CALL_ONSTATEREQUEST(a) s_callbacks.onStateRequest()
336#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200337
338static UserCallbackInfo * internalRequestTimedCallback
339 (RIL_TimedCallback callback, void *param,
340 const struct timeval *relativeTime);
341
342/** Index == requestNumber */
343static CommandInfo s_commands[] = {
344#include "ril_commands.h"
345};
346
Howard Subd82ef12015-04-12 10:25:05 +0200347static CommandInfo s_commands_v[] = {
348#include "ril_commands_vendor.h"
349};
350
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200351static UnsolResponseInfo s_unsolResponses[] = {
352#include "ril_unsol_commands.h"
353};
354
Howard Subd82ef12015-04-12 10:25:05 +0200355static UnsolResponseInfo s_unsolResponses_v[] = {
356#include "ril_unsol_commands_vendor.h"
357};
358
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200359/* For older RILs that do not support new commands RIL_REQUEST_VOICE_RADIO_TECH and
360 RIL_UNSOL_VOICE_RADIO_TECH_CHANGED messages, decode the voice radio tech from
361 radio state message and store it. Every time there is a change in Radio State
362 check to see if voice radio tech changes and notify telephony
363 */
364int voiceRadioTech = -1;
365
366/* For older RILs that do not support new commands RIL_REQUEST_GET_CDMA_SUBSCRIPTION_SOURCE
367 and RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED messages, decode the subscription
368 source from radio state and store it. Every time there is a change in Radio State
369 check to see if subscription source changed and notify telephony
370 */
371int cdmaSubscriptionSource = -1;
372
373/* For older RILs that do not send RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, decode the
374 SIM/RUIM state from radio state and store it. Every time there is a change in Radio State,
375 check to see if SIM/RUIM status changed and notify telephony
376 */
377int simRuimStatus = -1;
378
Howard Sue32dbfd2015-01-07 15:55:57 +0800379static char * RIL_getRilSocketName() {
380 return rild;
381}
382
383extern "C"
Dheeraj Shettycc231012014-07-02 21:27:57 +0200384void RIL_setRilSocketName(const char * s) {
Howard Sue32dbfd2015-01-07 15:55:57 +0800385 strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
386}
387
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200388static char *
389strdupReadString(Parcel &p) {
390 size_t stringlen;
391 const char16_t *s16;
392
393 s16 = p.readString16Inplace(&stringlen);
394
395 return strndup16to8(s16, stringlen);
396}
397
Howard Subd82ef12015-04-12 10:25:05 +0200398static status_t
399readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
400 size_t s16Len;
401 const char16_t *s16;
402
403 s16 = p.readString16Inplace(&s16Len);
404 if (s16 == NULL) {
405 return NO_MEMORY;
406 }
407 size_t strLen = strnlen16to8(s16, s16Len);
408 if ((strLen + 1) > maxLen) {
409 return NO_MEMORY;
410 }
411 if (strncpy16to8(str, s16, strLen) == NULL) {
412 return NO_MEMORY;
413 } else {
414 return NO_ERROR;
415 }
416}
417
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200418static void writeStringToParcel(Parcel &p, const char *s) {
419 char16_t *s16;
420 size_t s16_len;
421 s16 = strdup8to16(s, &s16_len);
422 p.writeString16(s16, s16_len);
423 free(s16);
424}
425
426
427static void
428memsetString (char *s) {
429 if (s != NULL) {
430 memset (s, 0, strlen(s));
431 }
432}
433
434void nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
435 const size_t* objects, size_t objectsSize,
436 void* cookie) {
437 // do nothing -- the data reference lives longer than the Parcel object
438}
439
440/**
441 * To be called from dispatch thread
442 * Issue a single local request, ensuring that the response
443 * is not sent back up to the command process
444 */
445static void
Howard Sue32dbfd2015-01-07 15:55:57 +0800446issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200447 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200448 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800449 /* Hook for current context */
450 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
451 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
452 /* pendingRequestsHook refer to &s_pendingRequests */
453 RequestInfo** pendingRequestsHook = &s_pendingRequests;
454
455#if (SIM_COUNT == 2)
456 if (socket_id == RIL_SOCKET_2) {
457 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
458 pendingRequestsHook = &s_pendingRequests_socket2;
459 }
460#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200461
462 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
463
464 pRI->local = 1;
465 pRI->token = 0xffffffff; // token is not used in this context
466
Howard Subd82ef12015-04-12 10:25:05 +0200467 /* Check vendor commands */
468 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
469 pRI->pCI = &(s_commands_v[request - RIL_VENDOR_COMMANDS_OFFSET]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200470 } else {
471 pRI->pCI = &(s_commands[request]);
472 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800473 pRI->socket_id = socket_id;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200474
Howard Sue32dbfd2015-01-07 15:55:57 +0800475 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200476 assert (ret == 0);
477
Howard Sue32dbfd2015-01-07 15:55:57 +0800478 pRI->p_next = *pendingRequestsHook;
479 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200480
Howard Sue32dbfd2015-01-07 15:55:57 +0800481 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200482 assert (ret == 0);
483
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200484 RLOGD("C[locl]> %s", requestToString(request));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200485
Howard Sue32dbfd2015-01-07 15:55:57 +0800486 CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200487}
488
Howard Subd82ef12015-04-12 10:25:05 +0200489
490
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200491static int
Howard Sue32dbfd2015-01-07 15:55:57 +0800492processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200493 Parcel p;
494 status_t status;
495 int32_t request;
496 int32_t token;
497 RequestInfo *pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200498 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +0800499 /* Hook for current context */
500 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
501 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
502 /* pendingRequestsHook refer to &s_pendingRequests */
503 RequestInfo** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200504
505 p.setData((uint8_t *) buffer, buflen);
506
507 // status checked at end
508 status = p.readInt32(&request);
509 status = p.readInt32 (&token);
510
Howard Sue32dbfd2015-01-07 15:55:57 +0800511#if (SIM_COUNT >= 2)
512 if (socket_id == RIL_SOCKET_2) {
513 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
514 pendingRequestsHook = &s_pendingRequests_socket2;
515 }
516#if (SIM_COUNT >= 3)
517 else if (socket_id == RIL_SOCKET_3) {
518 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
519 pendingRequestsHook = &s_pendingRequests_socket3;
520 }
521#endif
522#if (SIM_COUNT >= 4)
523 else if (socket_id == RIL_SOCKET_4) {
524 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
525 pendingRequestsHook = &s_pendingRequests_socket4;
526 }
527#endif
528#endif
529
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200530 if (status != NO_ERROR) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200531 RLOGE("invalid request block");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200532 return 0;
533 }
534
Howard Subd82ef12015-04-12 10:25:05 +0200535 CommandInfo *pCI = NULL;
536 if (request > RIL_VENDOR_COMMANDS_OFFSET) {
537 int index = request - RIL_VENDOR_COMMANDS_OFFSET;
538 RLOGD("processCommandBuffer: samsung request=%d, index=%d",
539 request, index);
540 if (index < (int32_t)NUM_ELEMS(s_commands_v))
541 pCI = &(s_commands_v[index]);
542 } else {
543 if (request < (int32_t)NUM_ELEMS(s_commands))
544 pCI = &(s_commands[request]);
545 }
Howard Sue32dbfd2015-01-07 15:55:57 +0800546
Howard Subd82ef12015-04-12 10:25:05 +0200547 if (pCI == NULL) {
548 Parcel pErr;
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200549 RLOGE("unsupported request code %d token %d", request, token);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200550 // FIXME this should perhaps return a response
Howard Sue32dbfd2015-01-07 15:55:57 +0800551 pErr.writeInt32 (RESPONSE_SOLICITED);
552 pErr.writeInt32 (token);
553 pErr.writeInt32 (RIL_E_GENERIC_FAILURE);
554
555 sendResponse(pErr, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200556 return 0;
557 }
558
559 pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
560
561 pRI->token = token;
Howard Subd82ef12015-04-12 10:25:05 +0200562 pRI->pCI = pCI;
Howard Sue32dbfd2015-01-07 15:55:57 +0800563 pRI->socket_id = socket_id;
564
565 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200566 assert (ret == 0);
567
Howard Sue32dbfd2015-01-07 15:55:57 +0800568 pRI->p_next = *pendingRequestsHook;
569 *pendingRequestsHook = pRI;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200570
Howard Sue32dbfd2015-01-07 15:55:57 +0800571 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200572 assert (ret == 0);
573
574/* sLastDispatchedToken = token; */
575
576 pRI->pCI->dispatchFunction(p, pRI);
577
578 return 0;
579}
580
581static void
582invalidCommandBlock (RequestInfo *pRI) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +0200583 RLOGE("invalid command block for token %d request %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200584 pRI->token, requestToString(pRI->pCI->requestNumber));
585}
586
587/** Callee expects NULL */
588static void
589dispatchVoid (Parcel& p, RequestInfo *pRI) {
590 clearPrintBuf;
591 printRequest(pRI->token, pRI->pCI->requestNumber);
Howard Sue32dbfd2015-01-07 15:55:57 +0800592 CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200593}
594
595/** Callee expects const char * */
596static void
597dispatchString (Parcel& p, RequestInfo *pRI) {
598 status_t status;
599 size_t datalen;
600 size_t stringlen;
601 char *string8 = NULL;
602
603 string8 = strdupReadString(p);
604
605 startRequest;
606 appendPrintBuf("%s%s", printBuf, string8);
607 closeRequest;
608 printRequest(pRI->token, pRI->pCI->requestNumber);
609
Howard Sue32dbfd2015-01-07 15:55:57 +0800610 CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
611 sizeof(char *), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200612
613#ifdef MEMSET_FREED
614 memsetString(string8);
615#endif
616
617 free(string8);
618 return;
619invalid:
620 invalidCommandBlock(pRI);
621 return;
622}
623
624/** Callee expects const char ** */
625static void
626dispatchStrings (Parcel &p, RequestInfo *pRI) {
627 int32_t countStrings;
628 status_t status;
629 size_t datalen;
630 char **pStrings;
631
632 status = p.readInt32 (&countStrings);
633
634 if (status != NO_ERROR) {
635 goto invalid;
636 }
637
638 startRequest;
639 if (countStrings == 0) {
640 // just some non-null pointer
641 pStrings = (char **)alloca(sizeof(char *));
642 datalen = 0;
643 } else if (((int)countStrings) == -1) {
644 pStrings = NULL;
645 datalen = 0;
646 } else {
647 datalen = sizeof(char *) * countStrings;
648
649 pStrings = (char **)alloca(datalen);
650
651 for (int i = 0 ; i < countStrings ; i++) {
652 pStrings[i] = strdupReadString(p);
653 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
654 }
655 }
656 removeLastChar;
657 closeRequest;
658 printRequest(pRI->token, pRI->pCI->requestNumber);
659
Howard Sue32dbfd2015-01-07 15:55:57 +0800660 CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200661
662 if (pStrings != NULL) {
663 for (int i = 0 ; i < countStrings ; i++) {
664#ifdef MEMSET_FREED
665 memsetString (pStrings[i]);
666#endif
667 free(pStrings[i]);
668 }
669
670#ifdef MEMSET_FREED
671 memset(pStrings, 0, datalen);
672#endif
673 }
674
675 return;
676invalid:
677 invalidCommandBlock(pRI);
678 return;
679}
680
681/** Callee expects const int * */
682static void
683dispatchInts (Parcel &p, RequestInfo *pRI) {
684 int32_t count;
685 status_t status;
686 size_t datalen;
687 int *pInts;
688
689 status = p.readInt32 (&count);
690
691 if (status != NO_ERROR || count == 0) {
692 goto invalid;
693 }
694
695 datalen = sizeof(int) * count;
696 pInts = (int *)alloca(datalen);
697
698 startRequest;
699 for (int i = 0 ; i < count ; i++) {
700 int32_t t;
701
702 status = p.readInt32(&t);
703 pInts[i] = (int)t;
704 appendPrintBuf("%s%d,", printBuf, t);
705
706 if (status != NO_ERROR) {
707 goto invalid;
708 }
709 }
710 removeLastChar;
711 closeRequest;
712 printRequest(pRI->token, pRI->pCI->requestNumber);
713
Howard Sue32dbfd2015-01-07 15:55:57 +0800714 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
715 datalen, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200716
717#ifdef MEMSET_FREED
718 memset(pInts, 0, datalen);
719#endif
720
721 return;
722invalid:
723 invalidCommandBlock(pRI);
724 return;
725}
726
727
728/**
729 * Callee expects const RIL_SMS_WriteArgs *
730 * Payload is:
731 * int32_t status
732 * String pdu
733 */
734static void
735dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
736 RIL_SMS_WriteArgs args;
737 int32_t t;
738 status_t status;
739
Mark Salyzyn961fd022015-04-09 07:18:35 -0700740 RLOGD("dispatchSmsWrite");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200741 memset (&args, 0, sizeof(args));
742
743 status = p.readInt32(&t);
744 args.status = (int)t;
745
746 args.pdu = strdupReadString(p);
747
748 if (status != NO_ERROR || args.pdu == NULL) {
749 goto invalid;
750 }
751
752 args.smsc = strdupReadString(p);
753
754 startRequest;
755 appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
756 (char*)args.pdu, (char*)args.smsc);
757 closeRequest;
758 printRequest(pRI->token, pRI->pCI->requestNumber);
759
Howard Sue32dbfd2015-01-07 15:55:57 +0800760 CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200761
762#ifdef MEMSET_FREED
763 memsetString (args.pdu);
764#endif
765
766 free (args.pdu);
767
768#ifdef MEMSET_FREED
769 memset(&args, 0, sizeof(args));
770#endif
771
772 return;
773invalid:
774 invalidCommandBlock(pRI);
775 return;
776}
777
778/**
779 * Callee expects const RIL_Dial *
780 * Payload is:
781 * String address
782 * int32_t clir
783 */
784static void
785dispatchDial (Parcel &p, RequestInfo *pRI) {
786 RIL_Dial dial;
787 RIL_UUS_Info uusInfo;
788 int32_t sizeOfDial;
789 int32_t t;
790 int32_t uusPresent;
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +0200791#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Andreas Schneider29472682015-01-01 19:00:04 +0100792 char *csv;
793#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200794 status_t status;
795
Mark Salyzyn961fd022015-04-09 07:18:35 -0700796 RLOGD("dispatchDial");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200797 memset (&dial, 0, sizeof(dial));
798
799 dial.address = strdupReadString(p);
800
801 status = p.readInt32(&t);
802 dial.clir = (int)t;
803
804 if (status != NO_ERROR || dial.address == NULL) {
805 goto invalid;
806 }
807
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +0200808#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Andreas Schneider29472682015-01-01 19:00:04 +0100809 /* CallDetails.call_type */
810 status = p.readInt32(&t);
811 if (status != NO_ERROR) {
812 goto invalid;
813 }
814 /* CallDetails.call_domain */
815 p.readInt32(&t);
816 if (status != NO_ERROR) {
817 goto invalid;
818 }
819 /* CallDetails.getCsvFromExtra */
820 csv = strdupReadString(p);
821 if (csv == NULL) {
822 goto invalid;
823 }
824 free(csv);
825#endif
826
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200827 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
828 uusPresent = 0;
829 sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
830 } else {
831 status = p.readInt32(&uusPresent);
832
833 if (status != NO_ERROR) {
834 goto invalid;
835 }
836
837 if (uusPresent == 0) {
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +0200838#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200839 dial.uusInfo = NULL;
Andreas Schneiderf68609b2015-04-07 19:01:34 +0200840#elif defined(MODEM_TYPE_XMM6260)
Howard Sue32dbfd2015-01-07 15:55:57 +0800841 /* Samsung hack */
842 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
843 uusInfo.uusType = (RIL_UUS_Type) 0;
844 uusInfo.uusDcs = (RIL_UUS_DCS) 0;
845 uusInfo.uusData = NULL;
846 uusInfo.uusLength = 0;
847 dial.uusInfo = &uusInfo;
848#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200849 } else {
850 int32_t len;
851
852 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
853
854 status = p.readInt32(&t);
855 uusInfo.uusType = (RIL_UUS_Type) t;
856
857 status = p.readInt32(&t);
858 uusInfo.uusDcs = (RIL_UUS_DCS) t;
859
860 status = p.readInt32(&len);
861 if (status != NO_ERROR) {
862 goto invalid;
863 }
864
865 // The java code writes -1 for null arrays
866 if (((int) len) == -1) {
867 uusInfo.uusData = NULL;
868 len = 0;
869 } else {
870 uusInfo.uusData = (char*) p.readInplace(len);
871 }
872
873 uusInfo.uusLength = len;
874 dial.uusInfo = &uusInfo;
875 }
876 sizeOfDial = sizeof(dial);
877 }
878
879 startRequest;
880 appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
881 if (uusPresent) {
882 appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
883 dial.uusInfo->uusType, dial.uusInfo->uusDcs,
884 dial.uusInfo->uusLength);
885 }
886 closeRequest;
887 printRequest(pRI->token, pRI->pCI->requestNumber);
888
Howard Sue32dbfd2015-01-07 15:55:57 +0800889 CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200890
891#ifdef MEMSET_FREED
892 memsetString (dial.address);
893#endif
894
895 free (dial.address);
896
897#ifdef MEMSET_FREED
898 memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
899 memset(&dial, 0, sizeof(dial));
900#endif
901
902 return;
903invalid:
904 invalidCommandBlock(pRI);
905 return;
906}
907
908/**
909 * Callee expects const RIL_SIM_IO *
910 * Payload is:
911 * int32_t command
912 * int32_t fileid
913 * String path
914 * int32_t p1, p2, p3
915 * String data
916 * String pin2
917 * String aidPtr
918 */
919static void
920dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
921 union RIL_SIM_IO {
922 RIL_SIM_IO_v6 v6;
923 RIL_SIM_IO_v5 v5;
924 } simIO;
925
926 int32_t t;
927 int size;
928 status_t status;
929
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700930#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -0700931 RLOGD("dispatchSIM_IO");
Robert Greenwaltbc29c432015-04-29 16:57:39 -0700932#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200933 memset (&simIO, 0, sizeof(simIO));
934
935 // note we only check status at the end
936
937 status = p.readInt32(&t);
938 simIO.v6.command = (int)t;
939
940 status = p.readInt32(&t);
941 simIO.v6.fileid = (int)t;
942
943 simIO.v6.path = strdupReadString(p);
944
945 status = p.readInt32(&t);
946 simIO.v6.p1 = (int)t;
947
948 status = p.readInt32(&t);
949 simIO.v6.p2 = (int)t;
950
951 status = p.readInt32(&t);
952 simIO.v6.p3 = (int)t;
953
954 simIO.v6.data = strdupReadString(p);
955 simIO.v6.pin2 = strdupReadString(p);
956 simIO.v6.aidPtr = strdupReadString(p);
957
958 startRequest;
959 appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
960 simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
961 simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
962 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
963 closeRequest;
964 printRequest(pRI->token, pRI->pCI->requestNumber);
965
966 if (status != NO_ERROR) {
967 goto invalid;
968 }
969
970 size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
Howard Sue32dbfd2015-01-07 15:55:57 +0800971 CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +0200972
973#ifdef MEMSET_FREED
974 memsetString (simIO.v6.path);
975 memsetString (simIO.v6.data);
976 memsetString (simIO.v6.pin2);
977 memsetString (simIO.v6.aidPtr);
978#endif
979
980 free (simIO.v6.path);
981 free (simIO.v6.data);
982 free (simIO.v6.pin2);
983 free (simIO.v6.aidPtr);
984
985#ifdef MEMSET_FREED
986 memset(&simIO, 0, sizeof(simIO));
987#endif
988
989 return;
990invalid:
991 invalidCommandBlock(pRI);
992 return;
993}
994
995/**
Howard Sue32dbfd2015-01-07 15:55:57 +0800996 * Callee expects const RIL_SIM_APDU *
997 * Payload is:
998 * int32_t sessionid
999 * int32_t cla
1000 * int32_t instruction
1001 * int32_t p1, p2, p3
1002 * String data
1003 */
1004static void
1005dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
1006 int32_t t;
1007 status_t status;
1008 RIL_SIM_APDU apdu;
1009
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001010#if VDBG
Mark Salyzyn961fd022015-04-09 07:18:35 -07001011 RLOGD("dispatchSIM_APDU");
Robert Greenwaltbc29c432015-04-29 16:57:39 -07001012#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08001013 memset (&apdu, 0, sizeof(RIL_SIM_APDU));
1014
1015 // Note we only check status at the end. Any single failure leads to
1016 // subsequent reads filing.
1017 status = p.readInt32(&t);
1018 apdu.sessionid = (int)t;
1019
1020 status = p.readInt32(&t);
1021 apdu.cla = (int)t;
1022
1023 status = p.readInt32(&t);
1024 apdu.instruction = (int)t;
1025
1026 status = p.readInt32(&t);
1027 apdu.p1 = (int)t;
1028
1029 status = p.readInt32(&t);
1030 apdu.p2 = (int)t;
1031
1032 status = p.readInt32(&t);
1033 apdu.p3 = (int)t;
1034
1035 apdu.data = strdupReadString(p);
1036
1037 startRequest;
1038 appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
1039 printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
1040 apdu.p3, (char*)apdu.data);
1041 closeRequest;
1042 printRequest(pRI->token, pRI->pCI->requestNumber);
1043
1044 if (status != NO_ERROR) {
1045 goto invalid;
1046 }
1047
1048 CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);
1049
1050#ifdef MEMSET_FREED
1051 memsetString(apdu.data);
1052#endif
1053 free(apdu.data);
1054
1055#ifdef MEMSET_FREED
1056 memset(&apdu, 0, sizeof(RIL_SIM_APDU));
1057#endif
1058
1059 return;
1060invalid:
1061 invalidCommandBlock(pRI);
1062 return;
1063}
1064
Howard Subd82ef12015-04-12 10:25:05 +02001065
Howard Sue32dbfd2015-01-07 15:55:57 +08001066/**
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001067 * Callee expects const RIL_CallForwardInfo *
1068 * Payload is:
1069 * int32_t status/action
1070 * int32_t reason
1071 * int32_t serviceCode
1072 * int32_t toa
1073 * String number (0 length -> null)
1074 * int32_t timeSeconds
1075 */
1076static void
1077dispatchCallForward(Parcel &p, RequestInfo *pRI) {
1078 RIL_CallForwardInfo cff;
1079 int32_t t;
1080 status_t status;
1081
Mark Salyzyn961fd022015-04-09 07:18:35 -07001082 RLOGD("dispatchCallForward");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001083 memset (&cff, 0, sizeof(cff));
1084
1085 // note we only check status at the end
1086
1087 status = p.readInt32(&t);
1088 cff.status = (int)t;
1089
1090 status = p.readInt32(&t);
1091 cff.reason = (int)t;
1092
1093 status = p.readInt32(&t);
1094 cff.serviceClass = (int)t;
1095
1096 status = p.readInt32(&t);
1097 cff.toa = (int)t;
1098
1099 cff.number = strdupReadString(p);
1100
1101 status = p.readInt32(&t);
1102 cff.timeSeconds = (int)t;
1103
1104 if (status != NO_ERROR) {
1105 goto invalid;
1106 }
1107
1108 // special case: number 0-length fields is null
1109
1110 if (cff.number != NULL && strlen (cff.number) == 0) {
1111 cff.number = NULL;
1112 }
1113
1114 startRequest;
1115 appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
1116 cff.status, cff.reason, cff.serviceClass, cff.toa,
1117 (char*)cff.number, cff.timeSeconds);
1118 closeRequest;
1119 printRequest(pRI->token, pRI->pCI->requestNumber);
1120
Howard Sue32dbfd2015-01-07 15:55:57 +08001121 CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001122
1123#ifdef MEMSET_FREED
1124 memsetString(cff.number);
1125#endif
1126
1127 free (cff.number);
1128
1129#ifdef MEMSET_FREED
1130 memset(&cff, 0, sizeof(cff));
1131#endif
1132
1133 return;
1134invalid:
1135 invalidCommandBlock(pRI);
1136 return;
1137}
1138
1139
1140static void
1141dispatchRaw(Parcel &p, RequestInfo *pRI) {
1142 int32_t len;
1143 status_t status;
1144 const void *data;
1145
1146 status = p.readInt32(&len);
1147
1148 if (status != NO_ERROR) {
1149 goto invalid;
1150 }
1151
1152 // The java code writes -1 for null arrays
1153 if (((int)len) == -1) {
1154 data = NULL;
1155 len = 0;
1156 }
1157
1158 data = p.readInplace(len);
1159
1160 startRequest;
1161 appendPrintBuf("%sraw_size=%d", printBuf, len);
1162 closeRequest;
1163 printRequest(pRI->token, pRI->pCI->requestNumber);
1164
Howard Sue32dbfd2015-01-07 15:55:57 +08001165 CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001166
1167 return;
1168invalid:
1169 invalidCommandBlock(pRI);
1170 return;
1171}
1172
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001173static status_t
1174constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001175 int32_t t;
1176 uint8_t ut;
1177 status_t status;
1178 int32_t digitCount;
1179 int digitLimit;
1180
1181 memset(&rcsm, 0, sizeof(rcsm));
1182
1183 status = p.readInt32(&t);
1184 rcsm.uTeleserviceID = (int) t;
1185
1186 status = p.read(&ut,sizeof(ut));
1187 rcsm.bIsServicePresent = (uint8_t) ut;
1188
1189 status = p.readInt32(&t);
1190 rcsm.uServicecategory = (int) t;
1191
1192 status = p.readInt32(&t);
1193 rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1194
1195 status = p.readInt32(&t);
1196 rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1197
1198 status = p.readInt32(&t);
1199 rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1200
1201 status = p.readInt32(&t);
1202 rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1203
1204 status = p.read(&ut,sizeof(ut));
1205 rcsm.sAddress.number_of_digits= (uint8_t) ut;
1206
1207 digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
1208 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1209 status = p.read(&ut,sizeof(ut));
1210 rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
1211 }
1212
1213 status = p.readInt32(&t);
1214 rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1215
1216 status = p.read(&ut,sizeof(ut));
1217 rcsm.sSubAddress.odd = (uint8_t) ut;
1218
1219 status = p.read(&ut,sizeof(ut));
1220 rcsm.sSubAddress.number_of_digits = (uint8_t) ut;
1221
1222 digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
1223 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1224 status = p.read(&ut,sizeof(ut));
1225 rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
1226 }
1227
1228 status = p.readInt32(&t);
1229 rcsm.uBearerDataLen = (int) t;
1230
1231 digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
1232 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
1233 status = p.read(&ut, sizeof(ut));
1234 rcsm.aBearerData[digitCount] = (uint8_t) ut;
1235 }
1236
1237 if (status != NO_ERROR) {
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001238 return status;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001239 }
1240
1241 startRequest;
1242 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
1243 sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
1244 printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
1245 rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
1246 closeRequest;
1247
1248 printRequest(pRI->token, pRI->pCI->requestNumber);
1249
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001250 return status;
1251}
1252
1253static void
1254dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
1255 RIL_CDMA_SMS_Message rcsm;
1256
Mark Salyzyn961fd022015-04-09 07:18:35 -07001257 RLOGD("dispatchCdmaSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001258 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1259 goto invalid;
1260 }
1261
Howard Sue32dbfd2015-01-07 15:55:57 +08001262 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001263
1264#ifdef MEMSET_FREED
1265 memset(&rcsm, 0, sizeof(rcsm));
1266#endif
1267
1268 return;
1269
1270invalid:
1271 invalidCommandBlock(pRI);
1272 return;
1273}
1274
1275static void
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001276dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1277 RIL_IMS_SMS_Message rism;
1278 RIL_CDMA_SMS_Message rcsm;
1279
Mark Salyzyn961fd022015-04-09 07:18:35 -07001280 RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001281
1282 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
1283 goto invalid;
1284 }
1285 memset(&rism, 0, sizeof(rism));
1286 rism.tech = RADIO_TECH_3GPP2;
1287 rism.retry = retry;
1288 rism.messageRef = messageRef;
1289 rism.message.cdmaMessage = &rcsm;
1290
Howard Sue32dbfd2015-01-07 15:55:57 +08001291 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001292 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001293 +sizeof(rcsm),pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001294
1295#ifdef MEMSET_FREED
1296 memset(&rcsm, 0, sizeof(rcsm));
1297 memset(&rism, 0, sizeof(rism));
1298#endif
1299
1300 return;
1301
1302invalid:
1303 invalidCommandBlock(pRI);
1304 return;
1305}
1306
1307static void
1308dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
1309 RIL_IMS_SMS_Message rism;
1310 int32_t countStrings;
1311 status_t status;
1312 size_t datalen;
1313 char **pStrings;
Mark Salyzyn961fd022015-04-09 07:18:35 -07001314 RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001315
1316 status = p.readInt32 (&countStrings);
1317
1318 if (status != NO_ERROR) {
1319 goto invalid;
1320 }
1321
1322 memset(&rism, 0, sizeof(rism));
1323 rism.tech = RADIO_TECH_3GPP;
1324 rism.retry = retry;
1325 rism.messageRef = messageRef;
1326
1327 startRequest;
Howard Sue32dbfd2015-01-07 15:55:57 +08001328 appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
1329 (int)rism.tech, (int)rism.retry, rism.messageRef);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001330 if (countStrings == 0) {
1331 // just some non-null pointer
1332 pStrings = (char **)alloca(sizeof(char *));
1333 datalen = 0;
1334 } else if (((int)countStrings) == -1) {
1335 pStrings = NULL;
1336 datalen = 0;
1337 } else {
1338 datalen = sizeof(char *) * countStrings;
1339
1340 pStrings = (char **)alloca(datalen);
1341
1342 for (int i = 0 ; i < countStrings ; i++) {
1343 pStrings[i] = strdupReadString(p);
1344 appendPrintBuf("%s%s,", printBuf, pStrings[i]);
1345 }
1346 }
1347 removeLastChar;
1348 closeRequest;
1349 printRequest(pRI->token, pRI->pCI->requestNumber);
1350
1351 rism.message.gsmMessage = pStrings;
Howard Sue32dbfd2015-01-07 15:55:57 +08001352 CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001353 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
Howard Sue32dbfd2015-01-07 15:55:57 +08001354 +datalen, pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001355
1356 if (pStrings != NULL) {
1357 for (int i = 0 ; i < countStrings ; i++) {
1358#ifdef MEMSET_FREED
1359 memsetString (pStrings[i]);
1360#endif
1361 free(pStrings[i]);
1362 }
1363
1364#ifdef MEMSET_FREED
1365 memset(pStrings, 0, datalen);
1366#endif
1367 }
1368
1369#ifdef MEMSET_FREED
1370 memset(&rism, 0, sizeof(rism));
1371#endif
1372 return;
1373invalid:
1374 ALOGE("dispatchImsGsmSms invalid block");
1375 invalidCommandBlock(pRI);
1376 return;
1377}
1378
1379static void
1380dispatchImsSms(Parcel &p, RequestInfo *pRI) {
1381 int32_t t;
1382 status_t status = p.readInt32(&t);
1383 RIL_RadioTechnologyFamily format;
1384 uint8_t retry;
1385 int32_t messageRef;
1386
Mark Salyzyn961fd022015-04-09 07:18:35 -07001387 RLOGD("dispatchImsSms");
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001388 if (status != NO_ERROR) {
1389 goto invalid;
1390 }
1391 format = (RIL_RadioTechnologyFamily) t;
1392
1393 // read retry field
1394 status = p.read(&retry,sizeof(retry));
1395 if (status != NO_ERROR) {
1396 goto invalid;
1397 }
1398 // read messageRef field
1399 status = p.read(&messageRef,sizeof(messageRef));
1400 if (status != NO_ERROR) {
1401 goto invalid;
1402 }
1403
1404 if (RADIO_TECH_3GPP == format) {
1405 dispatchImsGsmSms(p, pRI, retry, messageRef);
1406 } else if (RADIO_TECH_3GPP2 == format) {
1407 dispatchImsCdmaSms(p, pRI, retry, messageRef);
1408 } else {
1409 ALOGE("requestImsSendSMS invalid format value =%d", format);
1410 }
1411
1412 return;
1413
1414invalid:
1415 invalidCommandBlock(pRI);
1416 return;
1417}
1418
1419static void
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001420dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
1421 RIL_CDMA_SMS_Ack rcsa;
1422 int32_t t;
1423 status_t status;
1424 int32_t digitCount;
1425
Mark Salyzyn961fd022015-04-09 07:18:35 -07001426 RLOGD("dispatchCdmaSmsAck");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001427 memset(&rcsa, 0, sizeof(rcsa));
1428
1429 status = p.readInt32(&t);
1430 rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;
1431
1432 status = p.readInt32(&t);
1433 rcsa.uSMSCauseCode = (int) t;
1434
1435 if (status != NO_ERROR) {
1436 goto invalid;
1437 }
1438
1439 startRequest;
1440 appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
1441 printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
1442 closeRequest;
1443
1444 printRequest(pRI->token, pRI->pCI->requestNumber);
1445
Howard Sue32dbfd2015-01-07 15:55:57 +08001446 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001447
1448#ifdef MEMSET_FREED
1449 memset(&rcsa, 0, sizeof(rcsa));
1450#endif
1451
1452 return;
1453
1454invalid:
1455 invalidCommandBlock(pRI);
1456 return;
1457}
1458
1459static void
1460dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1461 int32_t t;
1462 status_t status;
1463 int32_t num;
1464
1465 status = p.readInt32(&num);
1466 if (status != NO_ERROR) {
1467 goto invalid;
1468 }
1469
Ethan Chend6e30652013-08-04 22:49:56 -07001470 {
1471 RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
1472 RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001473
Ethan Chend6e30652013-08-04 22:49:56 -07001474 startRequest;
1475 for (int i = 0 ; i < num ; i++ ) {
1476 gsmBciPtrs[i] = &gsmBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001477
Ethan Chend6e30652013-08-04 22:49:56 -07001478 status = p.readInt32(&t);
1479 gsmBci[i].fromServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001480
Ethan Chend6e30652013-08-04 22:49:56 -07001481 status = p.readInt32(&t);
1482 gsmBci[i].toServiceId = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001483
Ethan Chend6e30652013-08-04 22:49:56 -07001484 status = p.readInt32(&t);
1485 gsmBci[i].fromCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001486
Ethan Chend6e30652013-08-04 22:49:56 -07001487 status = p.readInt32(&t);
1488 gsmBci[i].toCodeScheme = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001489
Ethan Chend6e30652013-08-04 22:49:56 -07001490 status = p.readInt32(&t);
1491 gsmBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001492
Ethan Chend6e30652013-08-04 22:49:56 -07001493 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
1494 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
1495 gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
1496 gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
1497 gsmBci[i].selected);
1498 }
1499 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001500
Ethan Chend6e30652013-08-04 22:49:56 -07001501 if (status != NO_ERROR) {
1502 goto invalid;
1503 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001504
Howard Sue32dbfd2015-01-07 15:55:57 +08001505 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001506 gsmBciPtrs,
1507 num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001508 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001509
1510#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001511 memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
1512 memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001513#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001514 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001515
1516 return;
1517
1518invalid:
1519 invalidCommandBlock(pRI);
1520 return;
1521}
1522
1523static void
1524dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
1525 int32_t t;
1526 status_t status;
1527 int32_t num;
1528
1529 status = p.readInt32(&num);
1530 if (status != NO_ERROR) {
1531 goto invalid;
1532 }
1533
Ethan Chend6e30652013-08-04 22:49:56 -07001534 {
1535 RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
1536 RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001537
Ethan Chend6e30652013-08-04 22:49:56 -07001538 startRequest;
1539 for (int i = 0 ; i < num ; i++ ) {
1540 cdmaBciPtrs[i] = &cdmaBci[i];
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001541
Ethan Chend6e30652013-08-04 22:49:56 -07001542 status = p.readInt32(&t);
1543 cdmaBci[i].service_category = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001544
Ethan Chend6e30652013-08-04 22:49:56 -07001545 status = p.readInt32(&t);
1546 cdmaBci[i].language = (int) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001547
Ethan Chend6e30652013-08-04 22:49:56 -07001548 status = p.readInt32(&t);
1549 cdmaBci[i].selected = (uint8_t) t;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001550
Ethan Chend6e30652013-08-04 22:49:56 -07001551 appendPrintBuf("%s [%d: service_category=%d, language =%d, \
1552 entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
1553 cdmaBci[i].language, cdmaBci[i].selected);
1554 }
1555 closeRequest;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001556
Ethan Chend6e30652013-08-04 22:49:56 -07001557 if (status != NO_ERROR) {
1558 goto invalid;
1559 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001560
Howard Sue32dbfd2015-01-07 15:55:57 +08001561 CALL_ONREQUEST(pRI->pCI->requestNumber,
Ethan Chend6e30652013-08-04 22:49:56 -07001562 cdmaBciPtrs,
1563 num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
Howard Sue32dbfd2015-01-07 15:55:57 +08001564 pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001565
1566#ifdef MEMSET_FREED
Ethan Chend6e30652013-08-04 22:49:56 -07001567 memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
1568 memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001569#endif
Ethan Chend6e30652013-08-04 22:49:56 -07001570 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001571
1572 return;
1573
1574invalid:
1575 invalidCommandBlock(pRI);
1576 return;
1577}
1578
1579static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
1580 RIL_CDMA_SMS_WriteArgs rcsw;
1581 int32_t t;
1582 uint32_t ut;
1583 uint8_t uct;
1584 status_t status;
1585 int32_t digitCount;
1586
1587 memset(&rcsw, 0, sizeof(rcsw));
1588
1589 status = p.readInt32(&t);
1590 rcsw.status = t;
1591
1592 status = p.readInt32(&t);
1593 rcsw.message.uTeleserviceID = (int) t;
1594
1595 status = p.read(&uct,sizeof(uct));
1596 rcsw.message.bIsServicePresent = (uint8_t) uct;
1597
1598 status = p.readInt32(&t);
1599 rcsw.message.uServicecategory = (int) t;
1600
1601 status = p.readInt32(&t);
1602 rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;
1603
1604 status = p.readInt32(&t);
1605 rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;
1606
1607 status = p.readInt32(&t);
1608 rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;
1609
1610 status = p.readInt32(&t);
1611 rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;
1612
1613 status = p.read(&uct,sizeof(uct));
1614 rcsw.message.sAddress.number_of_digits = (uint8_t) uct;
1615
1616 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_ADDRESS_MAX; digitCount ++) {
1617 status = p.read(&uct,sizeof(uct));
1618 rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
1619 }
1620
1621 status = p.readInt32(&t);
1622 rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;
1623
1624 status = p.read(&uct,sizeof(uct));
1625 rcsw.message.sSubAddress.odd = (uint8_t) uct;
1626
1627 status = p.read(&uct,sizeof(uct));
1628 rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;
1629
1630 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_SUBADDRESS_MAX; digitCount ++) {
1631 status = p.read(&uct,sizeof(uct));
1632 rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
1633 }
1634
1635 status = p.readInt32(&t);
1636 rcsw.message.uBearerDataLen = (int) t;
1637
1638 for(digitCount = 0 ; digitCount < RIL_CDMA_SMS_BEARER_DATA_MAX; digitCount ++) {
1639 status = p.read(&uct, sizeof(uct));
1640 rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
1641 }
1642
1643 if (status != NO_ERROR) {
1644 goto invalid;
1645 }
1646
1647 startRequest;
1648 appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
1649 message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
1650 message.sAddress.number_mode=%d, \
1651 message.sAddress.number_type=%d, ",
1652 printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
1653 rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
1654 rcsw.message.sAddress.number_mode,
1655 rcsw.message.sAddress.number_type);
1656 closeRequest;
1657
1658 printRequest(pRI->token, pRI->pCI->requestNumber);
1659
Howard Sue32dbfd2015-01-07 15:55:57 +08001660 CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001661
1662#ifdef MEMSET_FREED
1663 memset(&rcsw, 0, sizeof(rcsw));
1664#endif
1665
1666 return;
1667
1668invalid:
1669 invalidCommandBlock(pRI);
1670 return;
1671
1672}
1673
Ethan Chend6e30652013-08-04 22:49:56 -07001674// For backwards compatibility in RIL_REQUEST_SETUP_DATA_CALL.
1675// Version 4 of the RIL interface adds a new PDP type parameter to support
1676// IPv6 and dual-stack PDP contexts. When dealing with a previous version of
1677// RIL, remove the parameter from the request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001678static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
Ethan Chend6e30652013-08-04 22:49:56 -07001679 // In RIL v3, REQUEST_SETUP_DATA_CALL takes 6 parameters.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001680 const int numParamsRilV3 = 6;
1681
Ethan Chend6e30652013-08-04 22:49:56 -07001682 // The first bytes of the RIL parcel contain the request number and the
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001683 // serial number - see processCommandBuffer(). Copy them over too.
1684 int pos = p.dataPosition();
1685
1686 int numParams = p.readInt32();
1687 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
1688 Parcel p2;
1689 p2.appendFrom(&p, 0, pos);
1690 p2.writeInt32(numParamsRilV3);
1691 for(int i = 0; i < numParamsRilV3; i++) {
1692 p2.writeString16(p.readString16());
1693 }
1694 p2.setDataPosition(pos);
1695 dispatchStrings(p2, pRI);
1696 } else {
1697 p.setDataPosition(pos);
1698 dispatchStrings(p, pRI);
1699 }
1700}
1701
1702// For backwards compatibility with RILs that dont support RIL_REQUEST_VOICE_RADIO_TECH.
Ethan Chend6e30652013-08-04 22:49:56 -07001703// When all RILs handle this request, this function can be removed and
1704// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001705static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001706 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001707
1708 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1709 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1710 }
1711
Ethan Chend6e30652013-08-04 22:49:56 -07001712 // RILs that support RADIO_STATE_ON should support this request.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001713 if (RADIO_STATE_ON == state) {
1714 dispatchVoid(p, pRI);
1715 return;
1716 }
1717
Ethan Chend6e30652013-08-04 22:49:56 -07001718 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
1719 // will not support this new request either and decode Voice Radio Technology
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001720 // from Radio State
1721 voiceRadioTech = decodeVoiceRadioTechnology(state);
1722
1723 if (voiceRadioTech < 0)
1724 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1725 else
1726 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
1727}
1728
Ethan Chend6e30652013-08-04 22:49:56 -07001729// For backwards compatibility in RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE:.
1730// When all RILs handle this request, this function can be removed and
1731// the request can be sent directly to the RIL using dispatchVoid.
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001732static void dispatchCdmaSubscriptionSource(Parcel& p, RequestInfo *pRI) {
Howard Sue32dbfd2015-01-07 15:55:57 +08001733 RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001734
1735 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
1736 RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
1737 }
1738
1739 // RILs that support RADIO_STATE_ON should support this request.
1740 if (RADIO_STATE_ON == state) {
1741 dispatchVoid(p, pRI);
1742 return;
1743 }
1744
Ethan Chend6e30652013-08-04 22:49:56 -07001745 // For Older RILs, that do not support RADIO_STATE_ON, assume that they
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001746 // will not support this new request either and decode CDMA Subscription Source
Ethan Chend6e30652013-08-04 22:49:56 -07001747 // from Radio State
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02001748 cdmaSubscriptionSource = decodeCdmaSubscriptionSource(state);
1749
1750 if (cdmaSubscriptionSource < 0)
1751 RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
1752 else
1753 RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &cdmaSubscriptionSource, sizeof(int));
1754}
1755
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001756static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
1757{
1758 RIL_InitialAttachApn pf;
1759 int32_t t;
1760 status_t status;
1761
1762 memset(&pf, 0, sizeof(pf));
1763
1764 pf.apn = strdupReadString(p);
1765 pf.protocol = strdupReadString(p);
1766
1767 status = p.readInt32(&t);
1768 pf.authtype = (int) t;
1769
1770 pf.username = strdupReadString(p);
1771 pf.password = strdupReadString(p);
1772
1773 startRequest;
1774 appendPrintBuf("%sapn=%s, protocol=%s, auth_type=%d, username=%s, password=%s",
Andreas Schneidera8d09502015-06-23 18:41:38 +02001775 printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001776 closeRequest;
1777 printRequest(pRI->token, pRI->pCI->requestNumber);
1778
1779 if (status != NO_ERROR) {
1780 goto invalid;
1781 }
Howard Sue32dbfd2015-01-07 15:55:57 +08001782 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
Andrew Jiangca4a9a02014-01-18 18:04:08 -05001783
1784#ifdef MEMSET_FREED
1785 memsetString(pf.apn);
1786 memsetString(pf.protocol);
1787 memsetString(pf.username);
1788 memsetString(pf.password);
1789#endif
1790
1791 free(pf.apn);
1792 free(pf.protocol);
1793 free(pf.username);
1794 free(pf.password);
1795
1796#ifdef MEMSET_FREED
1797 memset(&pf, 0, sizeof(pf));
1798#endif
1799
1800 return;
1801invalid:
1802 invalidCommandBlock(pRI);
1803 return;
1804}
1805
Howard Sue32dbfd2015-01-07 15:55:57 +08001806static void dispatchNVReadItem(Parcel &p, RequestInfo *pRI) {
1807 RIL_NV_ReadItem nvri;
1808 int32_t t;
1809 status_t status;
1810
1811 memset(&nvri, 0, sizeof(nvri));
1812
1813 status = p.readInt32(&t);
1814 nvri.itemID = (RIL_NV_Item) t;
1815
1816 if (status != NO_ERROR) {
1817 goto invalid;
1818 }
1819
1820 startRequest;
1821 appendPrintBuf("%snvri.itemID=%d, ", printBuf, nvri.itemID);
1822 closeRequest;
1823
1824 printRequest(pRI->token, pRI->pCI->requestNumber);
1825
1826 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvri, sizeof(nvri), pRI, pRI->socket_id);
1827
1828#ifdef MEMSET_FREED
1829 memset(&nvri, 0, sizeof(nvri));
1830#endif
1831
1832 return;
1833
1834invalid:
1835 invalidCommandBlock(pRI);
1836 return;
1837}
1838
1839static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
1840 RIL_NV_WriteItem nvwi;
1841 int32_t t;
1842 status_t status;
1843
1844 memset(&nvwi, 0, sizeof(nvwi));
1845
1846 status = p.readInt32(&t);
1847 nvwi.itemID = (RIL_NV_Item) t;
1848
1849 nvwi.value = strdupReadString(p);
1850
1851 if (status != NO_ERROR || nvwi.value == NULL) {
1852 goto invalid;
1853 }
1854
1855 startRequest;
1856 appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
1857 nvwi.value);
1858 closeRequest;
1859
1860 printRequest(pRI->token, pRI->pCI->requestNumber);
1861
1862 CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);
1863
1864#ifdef MEMSET_FREED
1865 memsetString(nvwi.value);
1866#endif
1867
1868 free(nvwi.value);
1869
1870#ifdef MEMSET_FREED
1871 memset(&nvwi, 0, sizeof(nvwi));
1872#endif
1873
1874 return;
1875
1876invalid:
1877 invalidCommandBlock(pRI);
1878 return;
1879}
1880
1881
1882static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
1883 RIL_SelectUiccSub uicc_sub;
1884 status_t status;
1885 int32_t t;
1886 memset(&uicc_sub, 0, sizeof(uicc_sub));
1887
1888 status = p.readInt32(&t);
1889 if (status != NO_ERROR) {
1890 goto invalid;
1891 }
1892 uicc_sub.slot = (int) t;
1893
1894 status = p.readInt32(&t);
1895 if (status != NO_ERROR) {
1896 goto invalid;
1897 }
1898 uicc_sub.app_index = (int) t;
1899
1900 status = p.readInt32(&t);
1901 if (status != NO_ERROR) {
1902 goto invalid;
1903 }
1904 uicc_sub.sub_type = (RIL_SubscriptionType) t;
1905
1906 status = p.readInt32(&t);
1907 if (status != NO_ERROR) {
1908 goto invalid;
1909 }
1910 uicc_sub.act_status = (RIL_UiccSubActStatus) t;
1911
1912 startRequest;
1913 appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
1914 uicc_sub.act_status);
1915 RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
1916 uicc_sub.app_index, uicc_sub.act_status);
1917 closeRequest;
1918 printRequest(pRI->token, pRI->pCI->requestNumber);
1919
1920 CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);
1921
1922#ifdef MEMSET_FREED
1923 memset(&uicc_sub, 0, sizeof(uicc_sub));
1924#endif
1925 return;
1926
1927invalid:
1928 invalidCommandBlock(pRI);
1929 return;
1930}
1931
1932static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
1933{
1934 RIL_SimAuthentication pf;
1935 int32_t t;
1936 status_t status;
1937
1938 memset(&pf, 0, sizeof(pf));
1939
1940 status = p.readInt32(&t);
1941 pf.authContext = (int) t;
1942 pf.authData = strdupReadString(p);
1943 pf.aid = strdupReadString(p);
1944
1945 startRequest;
Andreas Schneidera8d09502015-06-23 18:41:38 +02001946 appendPrintBuf("authContext=%d, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
Howard Sue32dbfd2015-01-07 15:55:57 +08001947 closeRequest;
1948 printRequest(pRI->token, pRI->pCI->requestNumber);
1949
1950 if (status != NO_ERROR) {
1951 goto invalid;
1952 }
1953 CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);
1954
1955#ifdef MEMSET_FREED
1956 memsetString(pf.authData);
1957 memsetString(pf.aid);
1958#endif
1959
1960 free(pf.authData);
1961 free(pf.aid);
1962
1963#ifdef MEMSET_FREED
1964 memset(&pf, 0, sizeof(pf));
1965#endif
1966
1967 return;
1968invalid:
1969 invalidCommandBlock(pRI);
1970 return;
1971}
1972
1973static void dispatchDataProfile(Parcel &p, RequestInfo *pRI) {
1974 int32_t t;
1975 status_t status;
1976 int32_t num;
1977
1978 status = p.readInt32(&num);
1979 if (status != NO_ERROR) {
1980 goto invalid;
1981 }
1982
1983 {
1984 RIL_DataProfileInfo dataProfiles[num];
1985 RIL_DataProfileInfo *dataProfilePtrs[num];
1986
1987 startRequest;
1988 for (int i = 0 ; i < num ; i++ ) {
1989 dataProfilePtrs[i] = &dataProfiles[i];
1990
1991 status = p.readInt32(&t);
1992 dataProfiles[i].profileId = (int) t;
1993
1994 dataProfiles[i].apn = strdupReadString(p);
1995 dataProfiles[i].protocol = strdupReadString(p);
1996 status = p.readInt32(&t);
1997 dataProfiles[i].authType = (int) t;
1998
1999 dataProfiles[i].user = strdupReadString(p);
2000 dataProfiles[i].password = strdupReadString(p);
2001
2002 status = p.readInt32(&t);
2003 dataProfiles[i].type = (int) t;
2004
2005 status = p.readInt32(&t);
2006 dataProfiles[i].maxConnsTime = (int) t;
2007 status = p.readInt32(&t);
2008 dataProfiles[i].maxConns = (int) t;
2009 status = p.readInt32(&t);
2010 dataProfiles[i].waitTime = (int) t;
2011
2012 status = p.readInt32(&t);
2013 dataProfiles[i].enabled = (int) t;
2014
2015 appendPrintBuf("%s [%d: profileId=%d, apn =%s, protocol =%s, authType =%d, \
2016 user =%s, password =%s, type =%d, maxConnsTime =%d, maxConns =%d, \
2017 waitTime =%d, enabled =%d]", printBuf, i, dataProfiles[i].profileId,
2018 dataProfiles[i].apn, dataProfiles[i].protocol, dataProfiles[i].authType,
2019 dataProfiles[i].user, dataProfiles[i].password, dataProfiles[i].type,
2020 dataProfiles[i].maxConnsTime, dataProfiles[i].maxConns,
2021 dataProfiles[i].waitTime, dataProfiles[i].enabled);
2022 }
2023 closeRequest;
2024 printRequest(pRI->token, pRI->pCI->requestNumber);
2025
2026 if (status != NO_ERROR) {
2027 goto invalid;
2028 }
2029 CALL_ONREQUEST(pRI->pCI->requestNumber,
2030 dataProfilePtrs,
2031 num * sizeof(RIL_DataProfileInfo *),
2032 pRI, pRI->socket_id);
2033
2034#ifdef MEMSET_FREED
2035 memset(dataProfiles, 0, num * sizeof(RIL_DataProfileInfo));
2036 memset(dataProfilePtrs, 0, num * sizeof(RIL_DataProfileInfo *));
2037#endif
2038 }
2039
2040 return;
2041
2042invalid:
2043 invalidCommandBlock(pRI);
2044 return;
2045}
2046
Howard Subd82ef12015-04-12 10:25:05 +02002047static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
2048 RIL_RadioCapability rc;
2049 int32_t t;
2050 status_t status;
2051
2052 memset (&rc, 0, sizeof(RIL_RadioCapability));
2053
2054 status = p.readInt32(&t);
2055 rc.version = (int)t;
2056 if (status != NO_ERROR) {
2057 goto invalid;
2058 }
2059
2060 status = p.readInt32(&t);
2061 rc.session= (int)t;
2062 if (status != NO_ERROR) {
2063 goto invalid;
2064 }
2065
2066 status = p.readInt32(&t);
2067 rc.phase= (int)t;
2068 if (status != NO_ERROR) {
2069 goto invalid;
2070 }
2071
2072 status = p.readInt32(&t);
2073 rc.rat = (int)t;
2074 if (status != NO_ERROR) {
2075 goto invalid;
2076 }
2077
2078 status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
2079 if (status != NO_ERROR) {
2080 goto invalid;
2081 }
2082
2083 status = p.readInt32(&t);
2084 rc.status = (int)t;
2085
2086 if (status != NO_ERROR) {
2087 goto invalid;
2088 }
2089
2090 startRequest;
2091 appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
Andreas Schneidera8d09502015-06-23 18:41:38 +02002092 logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
2093 rc.phase, rc.rat, rc.logicalModemUuid, rc.status);
Howard Subd82ef12015-04-12 10:25:05 +02002094
2095 closeRequest;
2096 printRequest(pRI->token, pRI->pCI->requestNumber);
2097
2098 CALL_ONREQUEST(pRI->pCI->requestNumber,
2099 &rc,
2100 sizeof(RIL_RadioCapability),
2101 pRI, pRI->socket_id);
2102 return;
2103invalid:
2104 invalidCommandBlock(pRI);
2105 return;
2106}
2107
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002108static int
2109blockingWrite(int fd, const void *buffer, size_t len) {
2110 size_t writeOffset = 0;
2111 const uint8_t *toWrite;
2112
2113 toWrite = (const uint8_t *)buffer;
2114
2115 while (writeOffset < len) {
2116 ssize_t written;
2117 do {
2118 written = write (fd, toWrite + writeOffset,
2119 len - writeOffset);
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002120 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002121
2122 if (written >= 0) {
2123 writeOffset += written;
2124 } else { // written < 0
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002125 RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002126 close(fd);
2127 return -1;
2128 }
2129 }
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002130#if VDBG
Dheeraj Shettycc231012014-07-02 21:27:57 +02002131 RLOGE("RIL Response bytes written:%d", writeOffset);
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002132#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002133 return 0;
2134}
2135
2136static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002137sendResponseRaw (const void *data, size_t dataSize, RIL_SOCKET_ID socket_id) {
2138 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002139 int ret;
2140 uint32_t header;
Howard Sue32dbfd2015-01-07 15:55:57 +08002141 pthread_mutex_t * writeMutexHook = &s_writeMutex;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002142
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002143#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08002144 RLOGE("Send Response to %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07002145#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08002146
2147#if (SIM_COUNT >= 2)
2148 if (socket_id == RIL_SOCKET_2) {
2149 fd = s_ril_param_socket2.fdCommand;
2150 writeMutexHook = &s_writeMutex_socket2;
2151 }
2152#if (SIM_COUNT >= 3)
2153 else if (socket_id == RIL_SOCKET_3) {
2154 fd = s_ril_param_socket3.fdCommand;
2155 writeMutexHook = &s_writeMutex_socket3;
2156 }
2157#endif
2158#if (SIM_COUNT >= 4)
2159 else if (socket_id == RIL_SOCKET_4) {
2160 fd = s_ril_param_socket4.fdCommand;
2161 writeMutexHook = &s_writeMutex_socket4;
2162 }
2163#endif
2164#endif
2165 if (fd < 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002166 return -1;
2167 }
2168
Howard Subd82ef12015-04-12 10:25:05 +02002169 if (dataSize > MAX_COMMAND_BYTES) {
2170 RLOGE("RIL: packet larger than %u (%u)",
2171 MAX_COMMAND_BYTES, (unsigned int )dataSize);
2172
2173 return -1;
2174 }
2175
Howard Sue32dbfd2015-01-07 15:55:57 +08002176 pthread_mutex_lock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002177
2178 header = htonl(dataSize);
2179
2180 ret = blockingWrite(fd, (void *)&header, sizeof(header));
2181
2182 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002183 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002184 return ret;
2185 }
2186
2187 ret = blockingWrite(fd, data, dataSize);
2188
2189 if (ret < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002190 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002191 return ret;
2192 }
2193
Howard Sue32dbfd2015-01-07 15:55:57 +08002194 pthread_mutex_unlock(writeMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002195
2196 return 0;
2197}
2198
2199static int
Howard Sue32dbfd2015-01-07 15:55:57 +08002200sendResponse (Parcel &p, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002201 printResponse;
Howard Sue32dbfd2015-01-07 15:55:57 +08002202 return sendResponseRaw(p.data(), p.dataSize(), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002203}
2204
Howard Sue32dbfd2015-01-07 15:55:57 +08002205/** response is an int* pointing to an array of ints */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002206
2207static int
2208responseInts(Parcel &p, void *response, size_t responselen) {
2209 int numInts;
2210
2211 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002212 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002213 return RIL_ERRNO_INVALID_RESPONSE;
2214 }
2215 if (responselen % sizeof(int) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002216 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002217 (int)responselen, (int)sizeof(int));
2218 return RIL_ERRNO_INVALID_RESPONSE;
2219 }
2220
2221 int *p_int = (int *) response;
2222
Howard Sue32dbfd2015-01-07 15:55:57 +08002223 numInts = responselen / sizeof(int);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002224 p.writeInt32 (numInts);
2225
2226 /* each int*/
2227 startResponse;
2228 for (int i = 0 ; i < numInts ; i++) {
2229 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2230 p.writeInt32(p_int[i]);
2231 }
2232 removeLastChar;
2233 closeResponse;
2234
2235 return 0;
2236}
2237
Daniel Hillenbrandd0b84162015-04-12 11:53:23 +02002238static int
2239responseIntsGetPreferredNetworkType(Parcel &p, void *response, size_t responselen) {
2240 int numInts;
2241
2242 if (response == NULL && responselen != 0) {
2243 RLOGE("invalid response: NULL");
2244 return RIL_ERRNO_INVALID_RESPONSE;
2245 }
2246 if (responselen % sizeof(int) != 0) {
2247 RLOGE("responseInts: invalid response length %d expected multiple of %d\n",
2248 (int)responselen, (int)sizeof(int));
2249 return RIL_ERRNO_INVALID_RESPONSE;
2250 }
2251
2252 int *p_int = (int *) response;
2253
2254 numInts = responselen / sizeof(int);
2255 p.writeInt32 (numInts);
2256
2257 /* each int*/
2258 startResponse;
2259 for (int i = 0 ; i < numInts ; i++) {
2260 if (i == 0 && p_int[0] == 7) {
2261 RLOGD("REQUEST_GET_PREFERRED_NETWORK_TYPE: NETWORK_MODE_GLOBAL => NETWORK_MODE_WCDMA_PREF");
2262 p_int[0] = 0;
2263 }
2264 appendPrintBuf("%s%d,", printBuf, p_int[i]);
2265 p.writeInt32(p_int[i]);
2266 }
2267 removeLastChar;
2268 closeResponse;
2269
2270 return 0;
2271}
2272
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002273/** response is a char **, pointing to an array of char *'s
2274 The parcel will begin with the version */
2275static int responseStringsWithVersion(int version, Parcel &p, void *response, size_t responselen) {
2276 p.writeInt32(version);
2277 return responseStrings(p, response, responselen);
2278}
2279
2280/** response is a char **, pointing to an array of char *'s */
2281static int responseStrings(Parcel &p, void *response, size_t responselen) {
2282 return responseStrings(p, response, responselen, false);
2283}
2284
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302285static int responseStringsNetworks(Parcel &p, void *response, size_t responselen) {
2286 return responseStrings(p, response, responselen, true);
2287}
2288
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002289/** response is a char **, pointing to an array of char *'s */
2290static int responseStrings(Parcel &p, void *response, size_t responselen, bool network_search) {
2291 int numStrings;
2292
2293 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002294 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002295 return RIL_ERRNO_INVALID_RESPONSE;
2296 }
2297 if (responselen % sizeof(char *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002298 RLOGE("responseStrings: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002299 (int)responselen, (int)sizeof(char *));
2300 return RIL_ERRNO_INVALID_RESPONSE;
2301 }
2302
2303 if (response == NULL) {
2304 p.writeInt32 (0);
2305 } else {
2306 char **p_cur = (char **) response;
2307
2308 numStrings = responselen / sizeof(char *);
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302309 if (network_search) {
2310 p.writeInt32 ((numStrings / 5) * 4);
2311 } else {
2312 p.writeInt32 (numStrings);
2313 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002314
2315 /* each string*/
2316 startResponse;
2317 for (int i = 0 ; i < numStrings ; i++) {
NBruderman72edd422015-06-08 15:54:55 +03002318 if (network_search && ((i + 1) % 5 == 0))
Utkarsh Guptaf7a63e52015-05-10 16:53:37 +05302319 continue;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002320 appendPrintBuf("%s%s,", printBuf, (char*)p_cur[i]);
2321 writeStringToParcel (p, p_cur[i]);
2322 }
2323 removeLastChar;
2324 closeResponse;
2325 }
2326 return 0;
2327}
2328
Howard Subd82ef12015-04-12 10:25:05 +02002329
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002330/**
2331 * NULL strings are accepted
2332 * FIXME currently ignores responselen
2333 */
2334static int responseString(Parcel &p, void *response, size_t responselen) {
2335 /* one string only */
2336 startResponse;
2337 appendPrintBuf("%s%s", printBuf, (char*)response);
2338 closeResponse;
2339
2340 writeStringToParcel(p, (const char *)response);
2341
2342 return 0;
2343}
2344
2345static int responseVoid(Parcel &p, void *response, size_t responselen) {
2346 startResponse;
2347 removeLastChar;
2348 return 0;
2349}
2350
2351static int responseCallList(Parcel &p, void *response, size_t responselen) {
2352 int num;
2353
2354 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002355 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002356 return RIL_ERRNO_INVALID_RESPONSE;
2357 }
2358
2359 if (responselen % sizeof (RIL_Call *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002360 RLOGE("responseCallList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002361 (int)responselen, (int)sizeof (RIL_Call *));
2362 return RIL_ERRNO_INVALID_RESPONSE;
2363 }
2364
2365 startResponse;
2366 /* number of call info's */
2367 num = responselen / sizeof(RIL_Call *);
2368 p.writeInt32(num);
2369
2370 for (int i = 0 ; i < num ; i++) {
2371 RIL_Call *p_cur = ((RIL_Call **) response)[i];
2372 /* each call info */
2373 p.writeInt32(p_cur->state);
2374 p.writeInt32(p_cur->index);
2375 p.writeInt32(p_cur->toa);
2376 p.writeInt32(p_cur->isMpty);
2377 p.writeInt32(p_cur->isMT);
2378 p.writeInt32(p_cur->als);
2379 p.writeInt32(p_cur->isVoice);
Andreas Schneider29472682015-01-01 19:00:04 +01002380
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02002381#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Andreas Schneider29472682015-01-01 19:00:04 +01002382 p.writeInt32(p_cur->isVideo);
2383
2384 /* Pass CallDetails */
2385 p.writeInt32(0);
2386 p.writeInt32(0);
2387 writeStringToParcel(p, "");
2388#endif
2389
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002390 p.writeInt32(p_cur->isVoicePrivacy);
2391 writeStringToParcel(p, p_cur->number);
2392 p.writeInt32(p_cur->numberPresentation);
2393 writeStringToParcel(p, p_cur->name);
2394 p.writeInt32(p_cur->namePresentation);
2395 // Remove when partners upgrade to version 3
2396 if ((s_callbacks.version < 3) || (p_cur->uusInfo == NULL || p_cur->uusInfo->uusData == NULL)) {
2397 p.writeInt32(0); /* UUS Information is absent */
2398 } else {
2399 RIL_UUS_Info *uusInfo = p_cur->uusInfo;
2400 p.writeInt32(1); /* UUS Information is present */
2401 p.writeInt32(uusInfo->uusType);
2402 p.writeInt32(uusInfo->uusDcs);
2403 p.writeInt32(uusInfo->uusLength);
2404 p.write(uusInfo->uusData, uusInfo->uusLength);
2405 }
2406 appendPrintBuf("%s[id=%d,%s,toa=%d,",
2407 printBuf,
2408 p_cur->index,
2409 callStateToString(p_cur->state),
2410 p_cur->toa);
2411 appendPrintBuf("%s%s,%s,als=%d,%s,%s,",
2412 printBuf,
2413 (p_cur->isMpty)?"conf":"norm",
2414 (p_cur->isMT)?"mt":"mo",
2415 p_cur->als,
2416 (p_cur->isVoice)?"voc":"nonvoc",
2417 (p_cur->isVoicePrivacy)?"evp":"noevp");
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02002418#if defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Andreas Schneider29472682015-01-01 19:00:04 +01002419 appendPrintBuf("%s,%s,",
2420 printBuf,
2421 (p_cur->isVideo) ? "vid" : "novid");
2422#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002423 appendPrintBuf("%s%s,cli=%d,name='%s',%d]",
2424 printBuf,
2425 p_cur->number,
2426 p_cur->numberPresentation,
2427 p_cur->name,
2428 p_cur->namePresentation);
2429 }
2430 removeLastChar;
2431 closeResponse;
2432
2433 return 0;
2434}
2435
2436static int responseSMS(Parcel &p, void *response, size_t responselen) {
2437 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002438 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002439 return RIL_ERRNO_INVALID_RESPONSE;
2440 }
2441
2442 if (responselen != sizeof (RIL_SMS_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002443 RLOGE("invalid response length %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002444 (int)responselen, (int)sizeof (RIL_SMS_Response));
2445 return RIL_ERRNO_INVALID_RESPONSE;
2446 }
2447
2448 RIL_SMS_Response *p_cur = (RIL_SMS_Response *) response;
2449
2450 p.writeInt32(p_cur->messageRef);
2451 writeStringToParcel(p, p_cur->ackPDU);
2452 p.writeInt32(p_cur->errorCode);
2453
2454 startResponse;
2455 appendPrintBuf("%s%d,%s,%d", printBuf, p_cur->messageRef,
2456 (char*)p_cur->ackPDU, p_cur->errorCode);
2457 closeResponse;
2458
2459 return 0;
2460}
2461
2462static int responseDataCallListV4(Parcel &p, void *response, size_t responselen)
2463{
2464 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002465 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002466 return RIL_ERRNO_INVALID_RESPONSE;
2467 }
2468
2469 if (responselen % sizeof(RIL_Data_Call_Response_v4) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002470 RLOGE("responseDataCallListV4: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002471 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v4));
2472 return RIL_ERRNO_INVALID_RESPONSE;
2473 }
2474
Howard Sue32dbfd2015-01-07 15:55:57 +08002475 // Write version
2476 p.writeInt32(4);
2477
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002478 int num = responselen / sizeof(RIL_Data_Call_Response_v4);
2479 p.writeInt32(num);
2480
2481 RIL_Data_Call_Response_v4 *p_cur = (RIL_Data_Call_Response_v4 *) response;
2482 startResponse;
2483 int i;
2484 for (i = 0; i < num; i++) {
2485 p.writeInt32(p_cur[i].cid);
2486 p.writeInt32(p_cur[i].active);
2487 writeStringToParcel(p, p_cur[i].type);
2488 // apn is not used, so don't send.
2489 writeStringToParcel(p, p_cur[i].address);
2490 appendPrintBuf("%s[cid=%d,%s,%s,%s],", printBuf,
2491 p_cur[i].cid,
2492 (p_cur[i].active==0)?"down":"up",
2493 (char*)p_cur[i].type,
2494 (char*)p_cur[i].address);
2495 }
2496 removeLastChar;
2497 closeResponse;
2498
2499 return 0;
2500}
2501
Howard Sue32dbfd2015-01-07 15:55:57 +08002502static int responseDataCallListV6(Parcel &p, void *response, size_t responselen)
2503{
2504 if (response == NULL && responselen != 0) {
2505 RLOGE("invalid response: NULL");
2506 return RIL_ERRNO_INVALID_RESPONSE;
2507 }
2508
2509 if (responselen % sizeof(RIL_Data_Call_Response_v6) != 0) {
2510 RLOGE("responseDataCallListV6: invalid response length %d expected multiple of %d",
2511 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v6));
2512 return RIL_ERRNO_INVALID_RESPONSE;
2513 }
2514
2515 // Write version
2516 p.writeInt32(6);
2517
2518 int num = responselen / sizeof(RIL_Data_Call_Response_v6);
2519 p.writeInt32(num);
2520
2521 RIL_Data_Call_Response_v6 *p_cur = (RIL_Data_Call_Response_v6 *) response;
2522 startResponse;
2523 int i;
2524 for (i = 0; i < num; i++) {
2525 p.writeInt32((int)p_cur[i].status);
2526 p.writeInt32(p_cur[i].suggestedRetryTime);
2527 p.writeInt32(p_cur[i].cid);
2528 p.writeInt32(p_cur[i].active);
2529 writeStringToParcel(p, p_cur[i].type);
2530 writeStringToParcel(p, p_cur[i].ifname);
2531 writeStringToParcel(p, p_cur[i].addresses);
2532 writeStringToParcel(p, p_cur[i].dnses);
2533 writeStringToParcel(p, p_cur[i].addresses);
2534 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s],", printBuf,
2535 p_cur[i].status,
2536 p_cur[i].suggestedRetryTime,
2537 p_cur[i].cid,
2538 (p_cur[i].active==0)?"down":"up",
2539 (char*)p_cur[i].type,
2540 (char*)p_cur[i].ifname,
2541 (char*)p_cur[i].addresses,
2542 (char*)p_cur[i].dnses,
2543 (char*)p_cur[i].addresses);
2544 }
2545 removeLastChar;
2546 closeResponse;
2547
2548 return 0;
2549}
2550
Howard Subd82ef12015-04-12 10:25:05 +02002551static int responseDataCallListV9(Parcel &p, void *response, size_t responselen)
2552{
2553 if (response == NULL && responselen != 0) {
2554 RLOGE("invalid response: NULL");
2555 return RIL_ERRNO_INVALID_RESPONSE;
2556 }
2557
2558 if (responselen % sizeof(RIL_Data_Call_Response_v9) != 0) {
2559 RLOGE("responseDataCallListV9: invalid response length %d expected multiple of %d",
2560 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v9));
2561 return RIL_ERRNO_INVALID_RESPONSE;
2562 }
2563
2564 // Write version
2565 p.writeInt32(10);
2566
2567 int num = responselen / sizeof(RIL_Data_Call_Response_v9);
2568 p.writeInt32(num);
2569
2570 RIL_Data_Call_Response_v9 *p_cur = (RIL_Data_Call_Response_v9 *) response;
2571 startResponse;
2572 int i;
2573 for (i = 0; i < num; i++) {
2574 p.writeInt32((int)p_cur[i].status);
2575 p.writeInt32(p_cur[i].suggestedRetryTime);
2576 p.writeInt32(p_cur[i].cid);
2577 p.writeInt32(p_cur[i].active);
2578 writeStringToParcel(p, p_cur[i].type);
2579 writeStringToParcel(p, p_cur[i].ifname);
2580 writeStringToParcel(p, p_cur[i].addresses);
2581 writeStringToParcel(p, p_cur[i].dnses);
2582 writeStringToParcel(p, p_cur[i].gateways);
2583 writeStringToParcel(p, p_cur[i].pcscf);
2584 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s],", printBuf,
2585 p_cur[i].status,
2586 p_cur[i].suggestedRetryTime,
2587 p_cur[i].cid,
2588 (p_cur[i].active==0)?"down":"up",
2589 (char*)p_cur[i].type,
2590 (char*)p_cur[i].ifname,
2591 (char*)p_cur[i].addresses,
2592 (char*)p_cur[i].dnses,
2593 (char*)p_cur[i].gateways,
2594 (char*)p_cur[i].pcscf);
2595 }
2596 removeLastChar;
2597 closeResponse;
2598
2599 return 0;
2600}
2601
2602
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002603static int responseDataCallList(Parcel &p, void *response, size_t responselen)
2604{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002605 if (s_callbacks.version < 5) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002606 RLOGD("responseDataCallList: v4");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002607 return responseDataCallListV4(p, response, responselen);
Howard Subd82ef12015-04-12 10:25:05 +02002608 } else if (responselen % sizeof(RIL_Data_Call_Response_v6) == 0) {
2609 return responseDataCallListV6(p, response, responselen);
2610 } else if (responselen % sizeof(RIL_Data_Call_Response_v9) == 0) {
2611 return responseDataCallListV9(p, response, responselen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002612 } else {
2613 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002614 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002615 return RIL_ERRNO_INVALID_RESPONSE;
2616 }
2617
Howard Subd82ef12015-04-12 10:25:05 +02002618 if (responselen % sizeof(RIL_Data_Call_Response_v11) != 0) {
2619 RLOGE("invalid response length %d expected multiple of %d",
2620 (int)responselen, (int)sizeof(RIL_Data_Call_Response_v11));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002621 return RIL_ERRNO_INVALID_RESPONSE;
2622 }
2623
Howard Sue32dbfd2015-01-07 15:55:57 +08002624 // Write version
Howard Subd82ef12015-04-12 10:25:05 +02002625 p.writeInt32(11);
Howard Sue32dbfd2015-01-07 15:55:57 +08002626
Howard Subd82ef12015-04-12 10:25:05 +02002627 int num = responselen / sizeof(RIL_Data_Call_Response_v11);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002628 p.writeInt32(num);
2629
Howard Subd82ef12015-04-12 10:25:05 +02002630 RIL_Data_Call_Response_v11 *p_cur = (RIL_Data_Call_Response_v11 *) response;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002631 startResponse;
2632 int i;
2633 for (i = 0; i < num; i++) {
2634 p.writeInt32((int)p_cur[i].status);
2635 p.writeInt32(p_cur[i].suggestedRetryTime);
2636 p.writeInt32(p_cur[i].cid);
2637 p.writeInt32(p_cur[i].active);
2638 writeStringToParcel(p, p_cur[i].type);
2639 writeStringToParcel(p, p_cur[i].ifname);
2640 writeStringToParcel(p, p_cur[i].addresses);
2641 writeStringToParcel(p, p_cur[i].dnses);
Howard Sue32dbfd2015-01-07 15:55:57 +08002642 writeStringToParcel(p, p_cur[i].gateways);
2643 writeStringToParcel(p, p_cur[i].pcscf);
Howard Subd82ef12015-04-12 10:25:05 +02002644 p.writeInt32(p_cur[i].mtu);
2645 appendPrintBuf("%s[status=%d,retry=%d,cid=%d,%s,%s,%s,%s,%s,%s,%s,mtu=%d],", printBuf,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002646 p_cur[i].status,
2647 p_cur[i].suggestedRetryTime,
2648 p_cur[i].cid,
2649 (p_cur[i].active==0)?"down":"up",
2650 (char*)p_cur[i].type,
2651 (char*)p_cur[i].ifname,
2652 (char*)p_cur[i].addresses,
2653 (char*)p_cur[i].dnses,
Howard Sue32dbfd2015-01-07 15:55:57 +08002654 (char*)p_cur[i].gateways,
Howard Subd82ef12015-04-12 10:25:05 +02002655 (char*)p_cur[i].pcscf,
2656 p_cur[i].mtu);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002657 }
2658 removeLastChar;
2659 closeResponse;
2660 }
2661
2662 return 0;
2663}
2664
2665static int responseSetupDataCall(Parcel &p, void *response, size_t responselen)
2666{
2667 if (s_callbacks.version < 5) {
2668 return responseStringsWithVersion(s_callbacks.version, p, response, responselen);
2669 } else {
2670 return responseDataCallList(p, response, responselen);
2671 }
2672}
2673
2674static int responseRaw(Parcel &p, void *response, size_t responselen) {
2675 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002676 RLOGE("invalid response: NULL with responselen != 0");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002677 return RIL_ERRNO_INVALID_RESPONSE;
2678 }
2679
2680 // The java code reads -1 size as null byte array
2681 if (response == NULL) {
2682 p.writeInt32(-1);
2683 } else {
2684 p.writeInt32(responselen);
2685 p.write(response, responselen);
2686 }
2687
2688 return 0;
2689}
2690
2691
2692static int responseSIM_IO(Parcel &p, void *response, size_t responselen) {
2693 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002694 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002695 return RIL_ERRNO_INVALID_RESPONSE;
2696 }
2697
2698 if (responselen != sizeof (RIL_SIM_IO_Response) ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002699 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002700 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
2701 return RIL_ERRNO_INVALID_RESPONSE;
2702 }
2703
2704 RIL_SIM_IO_Response *p_cur = (RIL_SIM_IO_Response *) response;
2705 p.writeInt32(p_cur->sw1);
2706 p.writeInt32(p_cur->sw2);
2707 writeStringToParcel(p, p_cur->simResponse);
2708
2709 startResponse;
2710 appendPrintBuf("%ssw1=0x%X,sw2=0x%X,%s", printBuf, p_cur->sw1, p_cur->sw2,
2711 (char*)p_cur->simResponse);
2712 closeResponse;
2713
2714
2715 return 0;
2716}
2717
2718static int responseCallForwards(Parcel &p, void *response, size_t responselen) {
2719 int num;
2720
2721 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002722 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002723 return RIL_ERRNO_INVALID_RESPONSE;
2724 }
2725
2726 if (responselen % sizeof(RIL_CallForwardInfo *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002727 RLOGE("responseCallForwards: invalid response length %d expected multiple of %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002728 (int)responselen, (int)sizeof(RIL_CallForwardInfo *));
2729 return RIL_ERRNO_INVALID_RESPONSE;
2730 }
2731
2732 /* number of call info's */
2733 num = responselen / sizeof(RIL_CallForwardInfo *);
2734 p.writeInt32(num);
2735
2736 startResponse;
2737 for (int i = 0 ; i < num ; i++) {
2738 RIL_CallForwardInfo *p_cur = ((RIL_CallForwardInfo **) response)[i];
2739
2740 p.writeInt32(p_cur->status);
2741 p.writeInt32(p_cur->reason);
2742 p.writeInt32(p_cur->serviceClass);
2743 p.writeInt32(p_cur->toa);
2744 writeStringToParcel(p, p_cur->number);
2745 p.writeInt32(p_cur->timeSeconds);
2746 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
2747 (p_cur->status==1)?"enable":"disable",
2748 p_cur->reason, p_cur->serviceClass, p_cur->toa,
2749 (char*)p_cur->number,
2750 p_cur->timeSeconds);
2751 }
2752 removeLastChar;
2753 closeResponse;
2754
2755 return 0;
2756}
2757
2758static int responseSsn(Parcel &p, void *response, size_t responselen) {
2759 if (response == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002760 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002761 return RIL_ERRNO_INVALID_RESPONSE;
2762 }
2763
2764 if (responselen != sizeof(RIL_SuppSvcNotification)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002765 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002766 (int)responselen, (int)sizeof (RIL_SuppSvcNotification));
2767 return RIL_ERRNO_INVALID_RESPONSE;
2768 }
2769
2770 RIL_SuppSvcNotification *p_cur = (RIL_SuppSvcNotification *) response;
2771 p.writeInt32(p_cur->notificationType);
2772 p.writeInt32(p_cur->code);
2773 p.writeInt32(p_cur->index);
2774 p.writeInt32(p_cur->type);
2775 writeStringToParcel(p, p_cur->number);
2776
2777 startResponse;
2778 appendPrintBuf("%s%s,code=%d,id=%d,type=%d,%s", printBuf,
2779 (p_cur->notificationType==0)?"mo":"mt",
2780 p_cur->code, p_cur->index, p_cur->type,
2781 (char*)p_cur->number);
2782 closeResponse;
2783
2784 return 0;
2785}
2786
2787static int responseCellList(Parcel &p, void *response, size_t responselen) {
2788 int num;
2789
2790 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002791 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002792 return RIL_ERRNO_INVALID_RESPONSE;
2793 }
2794
2795 if (responselen % sizeof (RIL_NeighboringCell *) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002796 RLOGE("responseCellList: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002797 (int)responselen, (int)sizeof (RIL_NeighboringCell *));
2798 return RIL_ERRNO_INVALID_RESPONSE;
2799 }
2800
2801 startResponse;
2802 /* number of records */
2803 num = responselen / sizeof(RIL_NeighboringCell *);
2804 p.writeInt32(num);
2805
2806 for (int i = 0 ; i < num ; i++) {
2807 RIL_NeighboringCell *p_cur = ((RIL_NeighboringCell **) response)[i];
2808
2809 p.writeInt32(p_cur->rssi);
2810 writeStringToParcel (p, p_cur->cid);
2811
2812 appendPrintBuf("%s[cid=%s,rssi=%d],", printBuf,
2813 p_cur->cid, p_cur->rssi);
2814 }
2815 removeLastChar;
2816 closeResponse;
2817
2818 return 0;
2819}
2820
2821/**
2822 * Marshall the signalInfoRecord into the parcel if it exists.
2823 */
2824static void marshallSignalInfoRecord(Parcel &p,
2825 RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
2826 p.writeInt32(p_signalInfoRecord.isPresent);
2827 p.writeInt32(p_signalInfoRecord.signalType);
2828 p.writeInt32(p_signalInfoRecord.alertPitch);
2829 p.writeInt32(p_signalInfoRecord.signal);
2830}
2831
2832static int responseCdmaInformationRecords(Parcel &p,
2833 void *response, size_t responselen) {
2834 int num;
2835 char* string8 = NULL;
2836 int buffer_lenght;
2837 RIL_CDMA_InformationRecord *infoRec;
2838
2839 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002840 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002841 return RIL_ERRNO_INVALID_RESPONSE;
2842 }
2843
2844 if (responselen != sizeof (RIL_CDMA_InformationRecords)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08002845 RLOGE("responseCdmaInformationRecords: invalid response length %d expected multiple of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002846 (int)responselen, (int)sizeof (RIL_CDMA_InformationRecords *));
2847 return RIL_ERRNO_INVALID_RESPONSE;
2848 }
2849
2850 RIL_CDMA_InformationRecords *p_cur =
2851 (RIL_CDMA_InformationRecords *) response;
2852 num = MIN(p_cur->numberOfInfoRecs, RIL_CDMA_MAX_NUMBER_OF_INFO_RECS);
2853
2854 startResponse;
2855 p.writeInt32(num);
2856
2857 for (int i = 0 ; i < num ; i++) {
2858 infoRec = &p_cur->infoRec[i];
2859 p.writeInt32(infoRec->name);
2860 switch (infoRec->name) {
2861 case RIL_CDMA_DISPLAY_INFO_REC:
2862 case RIL_CDMA_EXTENDED_DISPLAY_INFO_REC:
2863 if (infoRec->rec.display.alpha_len >
2864 CDMA_ALPHA_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002865 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002866 expected not more than %d\n",
2867 (int)infoRec->rec.display.alpha_len,
2868 CDMA_ALPHA_INFO_BUFFER_LENGTH);
2869 return RIL_ERRNO_INVALID_RESPONSE;
2870 }
2871 string8 = (char*) malloc((infoRec->rec.display.alpha_len + 1)
2872 * sizeof(char) );
2873 for (int i = 0 ; i < infoRec->rec.display.alpha_len ; i++) {
2874 string8[i] = infoRec->rec.display.alpha_buf[i];
2875 }
2876 string8[(int)infoRec->rec.display.alpha_len] = '\0';
2877 writeStringToParcel(p, (const char*)string8);
2878 free(string8);
2879 string8 = NULL;
2880 break;
2881 case RIL_CDMA_CALLED_PARTY_NUMBER_INFO_REC:
2882 case RIL_CDMA_CALLING_PARTY_NUMBER_INFO_REC:
2883 case RIL_CDMA_CONNECTED_NUMBER_INFO_REC:
2884 if (infoRec->rec.number.len > CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002885 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002886 expected not more than %d\n",
2887 (int)infoRec->rec.number.len,
2888 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2889 return RIL_ERRNO_INVALID_RESPONSE;
2890 }
2891 string8 = (char*) malloc((infoRec->rec.number.len + 1)
2892 * sizeof(char) );
2893 for (int i = 0 ; i < infoRec->rec.number.len; i++) {
2894 string8[i] = infoRec->rec.number.buf[i];
2895 }
2896 string8[(int)infoRec->rec.number.len] = '\0';
2897 writeStringToParcel(p, (const char*)string8);
2898 free(string8);
2899 string8 = NULL;
2900 p.writeInt32(infoRec->rec.number.number_type);
2901 p.writeInt32(infoRec->rec.number.number_plan);
2902 p.writeInt32(infoRec->rec.number.pi);
2903 p.writeInt32(infoRec->rec.number.si);
2904 break;
2905 case RIL_CDMA_SIGNAL_INFO_REC:
2906 p.writeInt32(infoRec->rec.signal.isPresent);
2907 p.writeInt32(infoRec->rec.signal.signalType);
2908 p.writeInt32(infoRec->rec.signal.alertPitch);
2909 p.writeInt32(infoRec->rec.signal.signal);
2910
2911 appendPrintBuf("%sisPresent=%X, signalType=%X, \
2912 alertPitch=%X, signal=%X, ",
2913 printBuf, (int)infoRec->rec.signal.isPresent,
2914 (int)infoRec->rec.signal.signalType,
2915 (int)infoRec->rec.signal.alertPitch,
2916 (int)infoRec->rec.signal.signal);
2917 removeLastChar;
2918 break;
2919 case RIL_CDMA_REDIRECTING_NUMBER_INFO_REC:
2920 if (infoRec->rec.redir.redirectingNumber.len >
2921 CDMA_NUMBER_INFO_BUFFER_LENGTH) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002922 RLOGE("invalid display info response length %d \
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002923 expected not more than %d\n",
2924 (int)infoRec->rec.redir.redirectingNumber.len,
2925 CDMA_NUMBER_INFO_BUFFER_LENGTH);
2926 return RIL_ERRNO_INVALID_RESPONSE;
2927 }
2928 string8 = (char*) malloc((infoRec->rec.redir.redirectingNumber
2929 .len + 1) * sizeof(char) );
2930 for (int i = 0;
2931 i < infoRec->rec.redir.redirectingNumber.len;
2932 i++) {
2933 string8[i] = infoRec->rec.redir.redirectingNumber.buf[i];
2934 }
2935 string8[(int)infoRec->rec.redir.redirectingNumber.len] = '\0';
2936 writeStringToParcel(p, (const char*)string8);
2937 free(string8);
2938 string8 = NULL;
2939 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_type);
2940 p.writeInt32(infoRec->rec.redir.redirectingNumber.number_plan);
2941 p.writeInt32(infoRec->rec.redir.redirectingNumber.pi);
2942 p.writeInt32(infoRec->rec.redir.redirectingNumber.si);
2943 p.writeInt32(infoRec->rec.redir.redirectingReason);
2944 break;
2945 case RIL_CDMA_LINE_CONTROL_INFO_REC:
2946 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPolarityIncluded);
2947 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlToggle);
2948 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlReverse);
2949 p.writeInt32(infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2950
2951 appendPrintBuf("%slineCtrlPolarityIncluded=%d, \
2952 lineCtrlToggle=%d, lineCtrlReverse=%d, \
2953 lineCtrlPowerDenial=%d, ", printBuf,
2954 (int)infoRec->rec.lineCtrl.lineCtrlPolarityIncluded,
2955 (int)infoRec->rec.lineCtrl.lineCtrlToggle,
2956 (int)infoRec->rec.lineCtrl.lineCtrlReverse,
2957 (int)infoRec->rec.lineCtrl.lineCtrlPowerDenial);
2958 removeLastChar;
2959 break;
2960 case RIL_CDMA_T53_CLIR_INFO_REC:
2961 p.writeInt32((int)(infoRec->rec.clir.cause));
2962
2963 appendPrintBuf("%scause%d", printBuf, infoRec->rec.clir.cause);
2964 removeLastChar;
2965 break;
2966 case RIL_CDMA_T53_AUDIO_CONTROL_INFO_REC:
2967 p.writeInt32(infoRec->rec.audioCtrl.upLink);
2968 p.writeInt32(infoRec->rec.audioCtrl.downLink);
2969
2970 appendPrintBuf("%supLink=%d, downLink=%d, ", printBuf,
2971 infoRec->rec.audioCtrl.upLink,
2972 infoRec->rec.audioCtrl.downLink);
2973 removeLastChar;
2974 break;
2975 case RIL_CDMA_T53_RELEASE_INFO_REC:
2976 // TODO(Moto): See David Krause, he has the answer:)
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002977 RLOGE("RIL_CDMA_T53_RELEASE_INFO_REC: return INVALID_RESPONSE");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002978 return RIL_ERRNO_INVALID_RESPONSE;
2979 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002980 RLOGE("Incorrect name value");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002981 return RIL_ERRNO_INVALID_RESPONSE;
2982 }
2983 }
2984 closeResponse;
2985
2986 return 0;
2987}
2988
2989static int responseRilSignalStrength(Parcel &p,
2990 void *response, size_t responselen) {
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05302991 int gsmSignalStrength;
2992 int cdmaDbm;
2993 int evdoDbm;
2994
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002995 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02002996 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02002997 return RIL_ERRNO_INVALID_RESPONSE;
2998 }
2999
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003000 if (responselen >= sizeof (RIL_SignalStrength_v5)) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003001 RIL_SignalStrength_v10 *p_cur = ((RIL_SignalStrength_v10 *) response);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003002
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303003 gsmSignalStrength = p_cur->GW_SignalStrength.signalStrength & 0xFF;
Utkarsh Gupta8ede9fa2015-04-23 13:21:49 +05303004
3005#ifdef MODEM_TYPE_XMM6260
3006 if (gsmSignalStrength < 0 ||
3007 (gsmSignalStrength > 31 && p_cur->GW_SignalStrength.signalStrength != 99)) {
3008 gsmSignalStrength = p_cur->CDMA_SignalStrength.dbm;
3009 }
3010#else
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303011 if (gsmSignalStrength < 0) {
3012 gsmSignalStrength = 99;
3013 } else if (gsmSignalStrength > 31 && gsmSignalStrength != 99) {
3014 gsmSignalStrength = 31;
3015 }
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303016#endif
3017 p.writeInt32(gsmSignalStrength);
3018
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003019 p.writeInt32(p_cur->GW_SignalStrength.bitErrorRate);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303020
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02003021#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303022 cdmaDbm = p_cur->CDMA_SignalStrength.dbm & 0xFF;
3023 if (cdmaDbm < 0) {
3024 cdmaDbm = 99;
3025 } else if (cdmaDbm > 31 && cdmaDbm != 99) {
3026 cdmaDbm = 31;
3027 }
3028#else
Caio Schnepperec042542015-04-14 08:03:43 -03003029 cdmaDbm = p_cur->CDMA_SignalStrength.dbm;
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303030#endif
3031 p.writeInt32(cdmaDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003032 p.writeInt32(p_cur->CDMA_SignalStrength.ecio);
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303033
Christopher N. Hesse7bf409e2015-06-26 14:53:56 +02003034#if defined(MODEM_TYPE_XMM6262) || defined(MODEM_TYPE_XMM7260) || defined(MODEM_TYPE_M7450)
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303035 evdoDbm = p_cur->EVDO_SignalStrength.dbm & 0xFF;
3036 if (evdoDbm < 0) {
3037 evdoDbm = 99;
3038 } else if (evdoDbm > 31 && evdoDbm != 99) {
3039 evdoDbm = 31;
3040 }
3041#else
3042 evdoDbm = p_cur->EVDO_SignalStrength.dbm;
3043#endif
3044 p.writeInt32(evdoDbm);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003045 p.writeInt32(p_cur->EVDO_SignalStrength.ecio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003046 p.writeInt32(p_cur->EVDO_SignalStrength.signalNoiseRatio);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003047 if (responselen >= sizeof (RIL_SignalStrength_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003048 /*
Ethan Chend6e30652013-08-04 22:49:56 -07003049 * Fixup LTE for backwards compatibility
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003050 */
Ethan Chend6e30652013-08-04 22:49:56 -07003051 if (s_callbacks.version <= 6) {
3052 // signalStrength: -1 -> 99
3053 if (p_cur->LTE_SignalStrength.signalStrength == -1) {
3054 p_cur->LTE_SignalStrength.signalStrength = 99;
3055 }
3056 // rsrp: -1 -> INT_MAX all other negative value to positive.
3057 // So remap here
3058 if (p_cur->LTE_SignalStrength.rsrp == -1) {
3059 p_cur->LTE_SignalStrength.rsrp = INT_MAX;
3060 } else if (p_cur->LTE_SignalStrength.rsrp < -1) {
3061 p_cur->LTE_SignalStrength.rsrp = -p_cur->LTE_SignalStrength.rsrp;
3062 }
3063 // rsrq: -1 -> INT_MAX
3064 if (p_cur->LTE_SignalStrength.rsrq == -1) {
3065 p_cur->LTE_SignalStrength.rsrq = INT_MAX;
3066 }
3067 // Not remapping rssnr is already using INT_MAX
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003068
Ethan Chend6e30652013-08-04 22:49:56 -07003069 // cqi: -1 -> INT_MAX
3070 if (p_cur->LTE_SignalStrength.cqi == -1) {
3071 p_cur->LTE_SignalStrength.cqi = INT_MAX;
3072 }
3073 }
3074 p.writeInt32(p_cur->LTE_SignalStrength.signalStrength);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003075 p.writeInt32(p_cur->LTE_SignalStrength.rsrp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003076 p.writeInt32(p_cur->LTE_SignalStrength.rsrq);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003077 p.writeInt32(p_cur->LTE_SignalStrength.rssnr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003078 p.writeInt32(p_cur->LTE_SignalStrength.cqi);
Howard Sue32dbfd2015-01-07 15:55:57 +08003079 if (responselen >= sizeof (RIL_SignalStrength_v10)) {
3080 p.writeInt32(p_cur->TD_SCDMA_SignalStrength.rscp);
3081 } else {
3082 p.writeInt32(INT_MAX);
3083 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003084 } else {
Ethan Chend6e30652013-08-04 22:49:56 -07003085 p.writeInt32(99);
3086 p.writeInt32(INT_MAX);
3087 p.writeInt32(INT_MAX);
3088 p.writeInt32(INT_MAX);
3089 p.writeInt32(INT_MAX);
Howard Sue32dbfd2015-01-07 15:55:57 +08003090 p.writeInt32(INT_MAX);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003091 }
3092
3093 startResponse;
3094 appendPrintBuf("%s[signalStrength=%d,bitErrorRate=%d,\
3095 CDMA_SS.dbm=%d,CDMA_SSecio=%d,\
3096 EVDO_SS.dbm=%d,EVDO_SS.ecio=%d,\
3097 EVDO_SS.signalNoiseRatio=%d,\
3098 LTE_SS.signalStrength=%d,LTE_SS.rsrp=%d,LTE_SS.rsrq=%d,\
Howard Sue32dbfd2015-01-07 15:55:57 +08003099 LTE_SS.rssnr=%d,LTE_SS.cqi=%d,TDSCDMA_SS.rscp=%d]",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003100 printBuf,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303101 gsmSignalStrength,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003102 p_cur->GW_SignalStrength.bitErrorRate,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303103 cdmaDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003104 p_cur->CDMA_SignalStrength.ecio,
Utkarsh Gupta8a0d7402015-04-13 13:33:37 +05303105 evdoDbm,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003106 p_cur->EVDO_SignalStrength.ecio,
3107 p_cur->EVDO_SignalStrength.signalNoiseRatio,
3108 p_cur->LTE_SignalStrength.signalStrength,
3109 p_cur->LTE_SignalStrength.rsrp,
3110 p_cur->LTE_SignalStrength.rsrq,
3111 p_cur->LTE_SignalStrength.rssnr,
Howard Sue32dbfd2015-01-07 15:55:57 +08003112 p_cur->LTE_SignalStrength.cqi,
3113 p_cur->TD_SCDMA_SignalStrength.rscp);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003114 closeResponse;
3115
3116 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003117 RLOGE("invalid response length");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003118 return RIL_ERRNO_INVALID_RESPONSE;
3119 }
3120
3121 return 0;
3122}
3123
3124static int responseCallRing(Parcel &p, void *response, size_t responselen) {
3125 if ((response == NULL) || (responselen == 0)) {
3126 return responseVoid(p, response, responselen);
3127 } else {
3128 return responseCdmaSignalInfoRecord(p, response, responselen);
3129 }
3130}
3131
3132static int responseCdmaSignalInfoRecord(Parcel &p, void *response, size_t responselen) {
3133 if (response == NULL || responselen == 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003134 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003135 return RIL_ERRNO_INVALID_RESPONSE;
3136 }
3137
3138 if (responselen != sizeof (RIL_CDMA_SignalInfoRecord)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003139 RLOGE("invalid response length %d expected sizeof (RIL_CDMA_SignalInfoRecord) of %d\n",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003140 (int)responselen, (int)sizeof (RIL_CDMA_SignalInfoRecord));
3141 return RIL_ERRNO_INVALID_RESPONSE;
3142 }
3143
3144 startResponse;
3145
3146 RIL_CDMA_SignalInfoRecord *p_cur = ((RIL_CDMA_SignalInfoRecord *) response);
3147 marshallSignalInfoRecord(p, *p_cur);
3148
3149 appendPrintBuf("%s[isPresent=%d,signalType=%d,alertPitch=%d\
3150 signal=%d]",
3151 printBuf,
3152 p_cur->isPresent,
3153 p_cur->signalType,
3154 p_cur->alertPitch,
3155 p_cur->signal);
3156
3157 closeResponse;
3158 return 0;
3159}
3160
3161static int responseCdmaCallWaiting(Parcel &p, void *response,
3162 size_t responselen) {
3163 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003164 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003165 return RIL_ERRNO_INVALID_RESPONSE;
3166 }
3167
3168 if (responselen < sizeof(RIL_CDMA_CallWaiting_v6)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003169 RLOGW("Upgrade to ril version %d\n", RIL_VERSION);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003170 }
3171
3172 RIL_CDMA_CallWaiting_v6 *p_cur = ((RIL_CDMA_CallWaiting_v6 *) response);
3173
3174 writeStringToParcel(p, p_cur->number);
3175 p.writeInt32(p_cur->numberPresentation);
3176 writeStringToParcel(p, p_cur->name);
3177 marshallSignalInfoRecord(p, p_cur->signalInfoRecord);
3178
3179 if (responselen >= sizeof(RIL_CDMA_CallWaiting_v6)) {
3180 p.writeInt32(p_cur->number_type);
3181 p.writeInt32(p_cur->number_plan);
3182 } else {
3183 p.writeInt32(0);
3184 p.writeInt32(0);
3185 }
3186
3187 startResponse;
3188 appendPrintBuf("%snumber=%s,numberPresentation=%d, name=%s,\
3189 signalInfoRecord[isPresent=%d,signalType=%d,alertPitch=%d\
3190 signal=%d,number_type=%d,number_plan=%d]",
3191 printBuf,
3192 p_cur->number,
3193 p_cur->numberPresentation,
3194 p_cur->name,
3195 p_cur->signalInfoRecord.isPresent,
3196 p_cur->signalInfoRecord.signalType,
3197 p_cur->signalInfoRecord.alertPitch,
3198 p_cur->signalInfoRecord.signal,
3199 p_cur->number_type,
3200 p_cur->number_plan);
3201 closeResponse;
3202
3203 return 0;
3204}
3205
3206static int responseSimRefresh(Parcel &p, void *response, size_t responselen) {
3207 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003208 RLOGE("responseSimRefresh: invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003209 return RIL_ERRNO_INVALID_RESPONSE;
3210 }
3211
3212 startResponse;
3213 if (s_callbacks.version == 7) {
3214 RIL_SimRefreshResponse_v7 *p_cur = ((RIL_SimRefreshResponse_v7 *) response);
3215 p.writeInt32(p_cur->result);
3216 p.writeInt32(p_cur->ef_id);
3217 writeStringToParcel(p, p_cur->aid);
3218
3219 appendPrintBuf("%sresult=%d, ef_id=%d, aid=%s",
3220 printBuf,
3221 p_cur->result,
3222 p_cur->ef_id,
3223 p_cur->aid);
3224 } else {
3225 int *p_cur = ((int *) response);
3226 p.writeInt32(p_cur[0]);
3227 p.writeInt32(p_cur[1]);
3228 writeStringToParcel(p, NULL);
3229
3230 appendPrintBuf("%sresult=%d, ef_id=%d",
3231 printBuf,
3232 p_cur[0],
3233 p_cur[1]);
3234 }
3235 closeResponse;
3236
3237 return 0;
3238}
3239
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003240static int responseCellInfoList(Parcel &p, void *response, size_t responselen)
3241{
3242 if (response == NULL && responselen != 0) {
3243 RLOGE("invalid response: NULL");
3244 return RIL_ERRNO_INVALID_RESPONSE;
3245 }
3246
3247 if (responselen % sizeof(RIL_CellInfo) != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003248 RLOGE("responseCellInfoList: invalid response length %d expected multiple of %d",
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003249 (int)responselen, (int)sizeof(RIL_CellInfo));
3250 return RIL_ERRNO_INVALID_RESPONSE;
3251 }
3252
3253 int num = responselen / sizeof(RIL_CellInfo);
3254 p.writeInt32(num);
3255
3256 RIL_CellInfo *p_cur = (RIL_CellInfo *) response;
3257 startResponse;
3258 int i;
3259 for (i = 0; i < num; i++) {
3260 appendPrintBuf("%s[%d: type=%d,registered=%d,timeStampType=%d,timeStamp=%lld", printBuf, i,
3261 p_cur->cellInfoType, p_cur->registered, p_cur->timeStampType, p_cur->timeStamp);
3262 p.writeInt32((int)p_cur->cellInfoType);
3263 p.writeInt32(p_cur->registered);
3264 p.writeInt32(p_cur->timeStampType);
3265 p.writeInt64(p_cur->timeStamp);
3266 switch(p_cur->cellInfoType) {
3267 case RIL_CELL_INFO_TYPE_GSM: {
3268 appendPrintBuf("%s GSM id: mcc=%d,mnc=%d,lac=%d,cid=%d,", printBuf,
3269 p_cur->CellInfo.gsm.cellIdentityGsm.mcc,
3270 p_cur->CellInfo.gsm.cellIdentityGsm.mnc,
3271 p_cur->CellInfo.gsm.cellIdentityGsm.lac,
3272 p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3273 appendPrintBuf("%s gsmSS: ss=%d,ber=%d],", printBuf,
3274 p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength,
3275 p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3276
3277 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mcc);
3278 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.mnc);
3279 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.lac);
3280 p.writeInt32(p_cur->CellInfo.gsm.cellIdentityGsm.cid);
3281 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.signalStrength);
3282 p.writeInt32(p_cur->CellInfo.gsm.signalStrengthGsm.bitErrorRate);
3283 break;
3284 }
3285 case RIL_CELL_INFO_TYPE_WCDMA: {
3286 appendPrintBuf("%s WCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,psc=%d,", printBuf,
3287 p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc,
3288 p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc,
3289 p_cur->CellInfo.wcdma.cellIdentityWcdma.lac,
3290 p_cur->CellInfo.wcdma.cellIdentityWcdma.cid,
3291 p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3292 appendPrintBuf("%s wcdmaSS: ss=%d,ber=%d],", printBuf,
3293 p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength,
3294 p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3295
3296 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mcc);
3297 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.mnc);
3298 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.lac);
3299 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.cid);
3300 p.writeInt32(p_cur->CellInfo.wcdma.cellIdentityWcdma.psc);
3301 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.signalStrength);
3302 p.writeInt32(p_cur->CellInfo.wcdma.signalStrengthWcdma.bitErrorRate);
3303 break;
3304 }
3305 case RIL_CELL_INFO_TYPE_CDMA: {
3306 appendPrintBuf("%s CDMA id: nId=%d,sId=%d,bsId=%d,long=%d,lat=%d", printBuf,
3307 p_cur->CellInfo.cdma.cellIdentityCdma.networkId,
3308 p_cur->CellInfo.cdma.cellIdentityCdma.systemId,
3309 p_cur->CellInfo.cdma.cellIdentityCdma.basestationId,
3310 p_cur->CellInfo.cdma.cellIdentityCdma.longitude,
3311 p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3312
3313 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.networkId);
3314 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.systemId);
3315 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.basestationId);
3316 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.longitude);
3317 p.writeInt32(p_cur->CellInfo.cdma.cellIdentityCdma.latitude);
3318
3319 appendPrintBuf("%s cdmaSS: dbm=%d ecio=%d evdoSS: dbm=%d,ecio=%d,snr=%d", printBuf,
3320 p_cur->CellInfo.cdma.signalStrengthCdma.dbm,
3321 p_cur->CellInfo.cdma.signalStrengthCdma.ecio,
3322 p_cur->CellInfo.cdma.signalStrengthEvdo.dbm,
3323 p_cur->CellInfo.cdma.signalStrengthEvdo.ecio,
3324 p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3325
3326 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.dbm);
3327 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthCdma.ecio);
3328 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.dbm);
3329 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.ecio);
3330 p.writeInt32(p_cur->CellInfo.cdma.signalStrengthEvdo.signalNoiseRatio);
3331 break;
3332 }
3333 case RIL_CELL_INFO_TYPE_LTE: {
3334 appendPrintBuf("%s LTE id: mcc=%d,mnc=%d,ci=%d,pci=%d,tac=%d", printBuf,
3335 p_cur->CellInfo.lte.cellIdentityLte.mcc,
3336 p_cur->CellInfo.lte.cellIdentityLte.mnc,
3337 p_cur->CellInfo.lte.cellIdentityLte.ci,
3338 p_cur->CellInfo.lte.cellIdentityLte.pci,
3339 p_cur->CellInfo.lte.cellIdentityLte.tac);
3340
3341 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mcc);
3342 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.mnc);
3343 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.ci);
3344 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.pci);
3345 p.writeInt32(p_cur->CellInfo.lte.cellIdentityLte.tac);
3346
3347 appendPrintBuf("%s lteSS: ss=%d,rsrp=%d,rsrq=%d,rssnr=%d,cqi=%d,ta=%d", printBuf,
3348 p_cur->CellInfo.lte.signalStrengthLte.signalStrength,
3349 p_cur->CellInfo.lte.signalStrengthLte.rsrp,
3350 p_cur->CellInfo.lte.signalStrengthLte.rsrq,
3351 p_cur->CellInfo.lte.signalStrengthLte.rssnr,
3352 p_cur->CellInfo.lte.signalStrengthLte.cqi,
3353 p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3354 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.signalStrength);
3355 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrp);
3356 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rsrq);
3357 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.rssnr);
3358 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.cqi);
3359 p.writeInt32(p_cur->CellInfo.lte.signalStrengthLte.timingAdvance);
3360 break;
3361 }
Howard Sue32dbfd2015-01-07 15:55:57 +08003362 case RIL_CELL_INFO_TYPE_TD_SCDMA: {
3363 appendPrintBuf("%s TDSCDMA id: mcc=%d,mnc=%d,lac=%d,cid=%d,cpid=%d,", printBuf,
3364 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc,
3365 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc,
3366 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac,
3367 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid,
3368 p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3369 appendPrintBuf("%s tdscdmaSS: rscp=%d],", printBuf,
3370 p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3371
3372 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
3373 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
3374 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.lac);
3375 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cid);
3376 p.writeInt32(p_cur->CellInfo.tdscdma.cellIdentityTdscdma.cpid);
3377 p.writeInt32(p_cur->CellInfo.tdscdma.signalStrengthTdscdma.rscp);
3378 break;
3379 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003380 }
3381 p_cur += 1;
3382 }
3383 removeLastChar;
3384 closeResponse;
3385
3386 return 0;
3387}
3388
Howard Sue32dbfd2015-01-07 15:55:57 +08003389static int responseHardwareConfig(Parcel &p, void *response, size_t responselen)
3390{
3391 if (response == NULL && responselen != 0) {
3392 RLOGE("invalid response: NULL");
3393 return RIL_ERRNO_INVALID_RESPONSE;
3394 }
3395
3396 if (responselen % sizeof(RIL_HardwareConfig) != 0) {
3397 RLOGE("responseHardwareConfig: invalid response length %d expected multiple of %d",
3398 (int)responselen, (int)sizeof(RIL_HardwareConfig));
3399 return RIL_ERRNO_INVALID_RESPONSE;
3400 }
3401
3402 int num = responselen / sizeof(RIL_HardwareConfig);
3403 int i;
3404 RIL_HardwareConfig *p_cur = (RIL_HardwareConfig *) response;
3405
3406 p.writeInt32(num);
3407
3408 startResponse;
3409 for (i = 0; i < num; i++) {
3410 switch (p_cur[i].type) {
3411 case RIL_HARDWARE_CONFIG_MODEM: {
3412 writeStringToParcel(p, p_cur[i].uuid);
3413 p.writeInt32((int)p_cur[i].state);
3414 p.writeInt32(p_cur[i].cfg.modem.rat);
3415 p.writeInt32(p_cur[i].cfg.modem.maxVoice);
3416 p.writeInt32(p_cur[i].cfg.modem.maxData);
3417 p.writeInt32(p_cur[i].cfg.modem.maxStandby);
3418
3419 appendPrintBuf("%s modem: uuid=%s,state=%d,rat=%08x,maxV=%d,maxD=%d,maxS=%d", printBuf,
3420 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.modem.rat,
3421 p_cur[i].cfg.modem.maxVoice, p_cur[i].cfg.modem.maxData, p_cur[i].cfg.modem.maxStandby);
3422 break;
3423 }
3424 case RIL_HARDWARE_CONFIG_SIM: {
3425 writeStringToParcel(p, p_cur[i].uuid);
3426 p.writeInt32((int)p_cur[i].state);
3427 writeStringToParcel(p, p_cur[i].cfg.sim.modemUuid);
3428
3429 appendPrintBuf("%s sim: uuid=%s,state=%d,modem-uuid=%s", printBuf,
3430 p_cur[i].uuid, (int)p_cur[i].state, p_cur[i].cfg.sim.modemUuid);
3431 break;
3432 }
3433 }
3434 }
3435 removeLastChar;
3436 closeResponse;
3437 return 0;
3438}
3439
Howard Subd82ef12015-04-12 10:25:05 +02003440static int responseRadioCapability(Parcel &p, void *response, size_t responselen) {
3441 if (response == NULL) {
3442 RLOGE("invalid response: NULL");
3443 return RIL_ERRNO_INVALID_RESPONSE;
3444 }
3445
3446 if (responselen != sizeof (RIL_RadioCapability) ) {
3447 RLOGE("invalid response length was %d expected %d",
3448 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3449 return RIL_ERRNO_INVALID_RESPONSE;
3450 }
3451
3452 RIL_RadioCapability *p_cur = (RIL_RadioCapability *) response;
3453 p.writeInt32(p_cur->version);
3454 p.writeInt32(p_cur->session);
3455 p.writeInt32(p_cur->phase);
3456 p.writeInt32(p_cur->rat);
3457 writeStringToParcel(p, p_cur->logicalModemUuid);
3458 p.writeInt32(p_cur->status);
3459
3460 startResponse;
3461 appendPrintBuf("%s[version=%d,session=%d,phase=%d,\
Andreas Schneidera8d09502015-06-23 18:41:38 +02003462 rat=%d,logicalModemUuid=%s,status=%d]",
Howard Subd82ef12015-04-12 10:25:05 +02003463 printBuf,
3464 p_cur->version,
3465 p_cur->session,
3466 p_cur->phase,
3467 p_cur->rat,
3468 p_cur->logicalModemUuid,
3469 p_cur->status);
3470 closeResponse;
3471 return 0;
3472}
3473
3474static int responseSSData(Parcel &p, void *response, size_t responselen) {
3475 RLOGD("In responseSSData");
3476 int num;
3477
3478 if (response == NULL && responselen != 0) {
3479 RLOGE("invalid response length was %d expected %d",
3480 (int)responselen, (int)sizeof (RIL_SIM_IO_Response));
3481 return RIL_ERRNO_INVALID_RESPONSE;
3482 }
3483
3484 if (responselen != sizeof(RIL_StkCcUnsolSsResponse)) {
3485 RLOGE("invalid response length %d, expected %d",
3486 (int)responselen, (int)sizeof(RIL_StkCcUnsolSsResponse));
3487 return RIL_ERRNO_INVALID_RESPONSE;
3488 }
3489
3490 startResponse;
3491 RIL_StkCcUnsolSsResponse *p_cur = (RIL_StkCcUnsolSsResponse *) response;
3492 p.writeInt32(p_cur->serviceType);
3493 p.writeInt32(p_cur->requestType);
3494 p.writeInt32(p_cur->teleserviceType);
3495 p.writeInt32(p_cur->serviceClass);
3496 p.writeInt32(p_cur->result);
3497
3498 if (isServiceTypeCfQuery(p_cur->serviceType, p_cur->requestType)) {
3499 RLOGD("responseSSData CF type, num of Cf elements %d", p_cur->cfData.numValidIndexes);
3500 if (p_cur->cfData.numValidIndexes > NUM_SERVICE_CLASSES) {
3501 RLOGE("numValidIndexes is greater than max value %d, "
3502 "truncating it to max value", NUM_SERVICE_CLASSES);
3503 p_cur->cfData.numValidIndexes = NUM_SERVICE_CLASSES;
3504 }
3505 /* number of call info's */
3506 p.writeInt32(p_cur->cfData.numValidIndexes);
3507
3508 for (int i = 0; i < p_cur->cfData.numValidIndexes; i++) {
3509 RIL_CallForwardInfo cf = p_cur->cfData.cfInfo[i];
3510
3511 p.writeInt32(cf.status);
3512 p.writeInt32(cf.reason);
3513 p.writeInt32(cf.serviceClass);
3514 p.writeInt32(cf.toa);
3515 writeStringToParcel(p, cf.number);
3516 p.writeInt32(cf.timeSeconds);
3517 appendPrintBuf("%s[%s,reason=%d,cls=%d,toa=%d,%s,tout=%d],", printBuf,
3518 (cf.status==1)?"enable":"disable", cf.reason, cf.serviceClass, cf.toa,
3519 (char*)cf.number, cf.timeSeconds);
3520 RLOGD("Data: %d,reason=%d,cls=%d,toa=%d,num=%s,tout=%d],", cf.status,
3521 cf.reason, cf.serviceClass, cf.toa, (char*)cf.number, cf.timeSeconds);
3522 }
3523 } else {
3524 p.writeInt32 (SS_INFO_MAX);
3525
3526 /* each int*/
3527 for (int i = 0; i < SS_INFO_MAX; i++) {
3528 appendPrintBuf("%s%d,", printBuf, p_cur->ssInfo[i]);
3529 RLOGD("Data: %d",p_cur->ssInfo[i]);
3530 p.writeInt32(p_cur->ssInfo[i]);
3531 }
3532 }
3533 removeLastChar;
3534 closeResponse;
3535
3536 return 0;
3537}
3538
3539static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
3540 if ((reqType == SS_INTERROGATION) &&
3541 (serType == SS_CFU ||
3542 serType == SS_CF_BUSY ||
3543 serType == SS_CF_NO_REPLY ||
3544 serType == SS_CF_NOT_REACHABLE ||
3545 serType == SS_CF_ALL ||
3546 serType == SS_CF_ALL_CONDITIONAL)) {
3547 return true;
3548 }
3549 return false;
3550}
3551
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003552static void triggerEvLoop() {
3553 int ret;
3554 if (!pthread_equal(pthread_self(), s_tid_dispatch)) {
3555 /* trigger event loop to wakeup. No reason to do this,
3556 * if we're in the event loop thread */
3557 do {
3558 ret = write (s_fdWakeupWrite, " ", 1);
3559 } while (ret < 0 && errno == EINTR);
3560 }
3561}
3562
3563static void rilEventAddWakeup(struct ril_event *ev) {
3564 ril_event_add(ev);
3565 triggerEvLoop();
3566}
3567
3568static void sendSimStatusAppInfo(Parcel &p, int num_apps, RIL_AppStatus appStatus[]) {
3569 p.writeInt32(num_apps);
3570 startResponse;
3571 for (int i = 0; i < num_apps; i++) {
3572 p.writeInt32(appStatus[i].app_type);
3573 p.writeInt32(appStatus[i].app_state);
3574 p.writeInt32(appStatus[i].perso_substate);
3575 writeStringToParcel(p, (const char*)(appStatus[i].aid_ptr));
3576 writeStringToParcel(p, (const char*)
3577 (appStatus[i].app_label_ptr));
3578 p.writeInt32(appStatus[i].pin1_replaced);
3579 p.writeInt32(appStatus[i].pin1);
3580 p.writeInt32(appStatus[i].pin2);
3581 appendPrintBuf("%s[app_type=%d,app_state=%d,perso_substate=%d,\
3582 aid_ptr=%s,app_label_ptr=%s,pin1_replaced=%d,pin1=%d,pin2=%d],",
3583 printBuf,
3584 appStatus[i].app_type,
3585 appStatus[i].app_state,
3586 appStatus[i].perso_substate,
3587 appStatus[i].aid_ptr,
3588 appStatus[i].app_label_ptr,
3589 appStatus[i].pin1_replaced,
3590 appStatus[i].pin1,
3591 appStatus[i].pin2);
3592 }
3593 closeResponse;
3594}
3595
3596static int responseSimStatus(Parcel &p, void *response, size_t responselen) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003597 int i;
3598
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003599 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003600 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003601 return RIL_ERRNO_INVALID_RESPONSE;
3602 }
3603
3604 if (responselen == sizeof (RIL_CardStatus_v6)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003605 RIL_CardStatus_v6 *p_cur = ((RIL_CardStatus_v6 *) response);
3606
3607 p.writeInt32(p_cur->card_state);
3608 p.writeInt32(p_cur->universal_pin_state);
3609 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3610 p.writeInt32(p_cur->cdma_subscription_app_index);
3611 p.writeInt32(p_cur->ims_subscription_app_index);
3612
3613 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3614 } else if (responselen == sizeof (RIL_CardStatus_v5)) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003615 RIL_CardStatus_v5 *p_cur = ((RIL_CardStatus_v5 *) response);
3616
3617 p.writeInt32(p_cur->card_state);
3618 p.writeInt32(p_cur->universal_pin_state);
3619 p.writeInt32(p_cur->gsm_umts_subscription_app_index);
3620 p.writeInt32(p_cur->cdma_subscription_app_index);
3621 p.writeInt32(-1);
3622
3623 sendSimStatusAppInfo(p, p_cur->num_applications, p_cur->applications);
3624 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003625 RLOGE("responseSimStatus: A RilCardStatus_v6 or _v5 expected\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003626 return RIL_ERRNO_INVALID_RESPONSE;
3627 }
3628
3629 return 0;
3630}
3631
3632static int responseGsmBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3633 int num = responselen / sizeof(RIL_GSM_BroadcastSmsConfigInfo *);
3634 p.writeInt32(num);
3635
3636 startResponse;
3637 RIL_GSM_BroadcastSmsConfigInfo **p_cur =
3638 (RIL_GSM_BroadcastSmsConfigInfo **) response;
3639 for (int i = 0; i < num; i++) {
3640 p.writeInt32(p_cur[i]->fromServiceId);
3641 p.writeInt32(p_cur[i]->toServiceId);
3642 p.writeInt32(p_cur[i]->fromCodeScheme);
3643 p.writeInt32(p_cur[i]->toCodeScheme);
3644 p.writeInt32(p_cur[i]->selected);
3645
3646 appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId=%d, \
3647 fromCodeScheme=%d, toCodeScheme=%d, selected =%d]",
3648 printBuf, i, p_cur[i]->fromServiceId, p_cur[i]->toServiceId,
3649 p_cur[i]->fromCodeScheme, p_cur[i]->toCodeScheme,
3650 p_cur[i]->selected);
3651 }
3652 closeResponse;
3653
3654 return 0;
3655}
3656
3657static int responseCdmaBrSmsCnf(Parcel &p, void *response, size_t responselen) {
3658 RIL_CDMA_BroadcastSmsConfigInfo **p_cur =
3659 (RIL_CDMA_BroadcastSmsConfigInfo **) response;
3660
3661 int num = responselen / sizeof (RIL_CDMA_BroadcastSmsConfigInfo *);
3662 p.writeInt32(num);
3663
3664 startResponse;
3665 for (int i = 0 ; i < num ; i++ ) {
3666 p.writeInt32(p_cur[i]->service_category);
3667 p.writeInt32(p_cur[i]->language);
3668 p.writeInt32(p_cur[i]->selected);
3669
3670 appendPrintBuf("%s [%d: srvice_category=%d, language =%d, \
3671 selected =%d], ",
3672 printBuf, i, p_cur[i]->service_category, p_cur[i]->language,
3673 p_cur[i]->selected);
3674 }
3675 closeResponse;
3676
3677 return 0;
3678}
3679
3680static int responseCdmaSms(Parcel &p, void *response, size_t responselen) {
3681 int num;
3682 int digitCount;
3683 int digitLimit;
3684 uint8_t uct;
3685 void* dest;
3686
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003687 RLOGD("Inside responseCdmaSms");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003688
3689 if (response == NULL && responselen != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003690 RLOGE("invalid response: NULL");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003691 return RIL_ERRNO_INVALID_RESPONSE;
3692 }
3693
3694 if (responselen != sizeof(RIL_CDMA_SMS_Message)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003695 RLOGE("invalid response length was %d expected %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003696 (int)responselen, (int)sizeof(RIL_CDMA_SMS_Message));
3697 return RIL_ERRNO_INVALID_RESPONSE;
3698 }
3699
3700 RIL_CDMA_SMS_Message *p_cur = (RIL_CDMA_SMS_Message *) response;
3701 p.writeInt32(p_cur->uTeleserviceID);
3702 p.write(&(p_cur->bIsServicePresent),sizeof(uct));
3703 p.writeInt32(p_cur->uServicecategory);
3704 p.writeInt32(p_cur->sAddress.digit_mode);
3705 p.writeInt32(p_cur->sAddress.number_mode);
3706 p.writeInt32(p_cur->sAddress.number_type);
3707 p.writeInt32(p_cur->sAddress.number_plan);
3708 p.write(&(p_cur->sAddress.number_of_digits), sizeof(uct));
3709 digitLimit= MIN((p_cur->sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
3710 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3711 p.write(&(p_cur->sAddress.digits[digitCount]),sizeof(uct));
3712 }
3713
3714 p.writeInt32(p_cur->sSubAddress.subaddressType);
3715 p.write(&(p_cur->sSubAddress.odd),sizeof(uct));
3716 p.write(&(p_cur->sSubAddress.number_of_digits),sizeof(uct));
3717 digitLimit= MIN((p_cur->sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
3718 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3719 p.write(&(p_cur->sSubAddress.digits[digitCount]),sizeof(uct));
3720 }
3721
3722 digitLimit= MIN((p_cur->uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
3723 p.writeInt32(p_cur->uBearerDataLen);
3724 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
3725 p.write(&(p_cur->aBearerData[digitCount]), sizeof(uct));
3726 }
3727
3728 startResponse;
3729 appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
3730 sAddress.digit_mode=%d, sAddress.number_mode=%d, sAddress.number_type=%d, ",
3731 printBuf, p_cur->uTeleserviceID,p_cur->bIsServicePresent,p_cur->uServicecategory,
3732 p_cur->sAddress.digit_mode, p_cur->sAddress.number_mode,p_cur->sAddress.number_type);
3733 closeResponse;
3734
3735 return 0;
3736}
3737
Howard Sue32dbfd2015-01-07 15:55:57 +08003738static int responseDcRtInfo(Parcel &p, void *response, size_t responselen)
3739{
3740 int num = responselen / sizeof(RIL_DcRtInfo);
3741 if ((responselen % sizeof(RIL_DcRtInfo) != 0) || (num != 1)) {
3742 RLOGE("responseDcRtInfo: invalid response length %d expected multiple of %d",
3743 (int)responselen, (int)sizeof(RIL_DcRtInfo));
3744 return RIL_ERRNO_INVALID_RESPONSE;
3745 }
3746
3747 startResponse;
3748 RIL_DcRtInfo *pDcRtInfo = (RIL_DcRtInfo *)response;
3749 p.writeInt64(pDcRtInfo->time);
3750 p.writeInt32(pDcRtInfo->powerState);
3751 appendPrintBuf("%s[time=%d,powerState=%d]", printBuf,
3752 pDcRtInfo->time,
Andreas Schneidera8d09502015-06-23 18:41:38 +02003753 (int)pDcRtInfo->powerState);
Howard Sue32dbfd2015-01-07 15:55:57 +08003754 closeResponse;
3755
3756 return 0;
3757}
3758
fenglu9bdede02015-04-14 14:53:55 -07003759static int responseLceStatus(Parcel &p, void *response, size_t responselen) {
3760 if (response == NULL || responselen != sizeof(RIL_LceStatusInfo)) {
3761 if (response == NULL) {
3762 RLOGE("invalid response: NULL");
3763 }
3764 else {
3765 RLOGE("responseLceStatus: invalid response length %d expecting len: d%",
3766 sizeof(RIL_LceStatusInfo), responselen);
3767 }
3768 return RIL_ERRNO_INVALID_RESPONSE;
3769 }
3770
3771 RIL_LceStatusInfo *p_cur = (RIL_LceStatusInfo *)response;
3772 p.write((void *)p_cur, 1); // p_cur->lce_status takes one byte.
3773 p.writeInt32(p_cur->actual_interval_ms);
3774
3775 startResponse;
3776 appendPrintBuf("LCE Status: %d, actual_interval_ms: %d",
3777 p_cur->lce_status, p_cur->actual_interval_ms);
3778 closeResponse;
3779
3780 return 0;
3781}
3782
3783static int responseLceData(Parcel &p, void *response, size_t responselen) {
3784 if (response == NULL || responselen != sizeof(RIL_LceDataInfo)) {
3785 if (response == NULL) {
3786 RLOGE("invalid response: NULL");
3787 }
3788 else {
3789 RLOGE("responseLceData: invalid response length %d expecting len: d%",
3790 sizeof(RIL_LceDataInfo), responselen);
3791 }
3792 return RIL_ERRNO_INVALID_RESPONSE;
3793 }
3794
3795 RIL_LceDataInfo *p_cur = (RIL_LceDataInfo *)response;
3796 p.writeInt32(p_cur->last_hop_capacity_kbps);
3797
3798 /* p_cur->confidence_level and p_cur->lce_suspended take 1 byte each.*/
3799 p.write((void *)&(p_cur->confidence_level), 1);
3800 p.write((void *)&(p_cur->lce_suspended), 1);
3801
3802 startResponse;
3803 appendPrintBuf("LCE info received: capacity %d confidence level %d
3804 and suspended %d",
3805 p_cur->last_hop_capacity_kbps, p_cur->confidence_level,
3806 p_cur->lce_suspended);
3807 closeResponse;
3808
3809 return 0;
3810}
3811
Prerepa Viswanadham8e755592015-05-28 00:37:32 -07003812static int responseActivityData(Parcel &p, void *response, size_t responselen) {
3813 if (response == NULL || responselen != sizeof(RIL_ActivityStatsInfo)) {
3814 if (response == NULL) {
3815 RLOGE("invalid response: NULL");
3816 }
3817 else {
3818 RLOGE("responseActivityData: invalid response length %d expecting len: d%",
3819 sizeof(RIL_ActivityStatsInfo), responselen);
3820 }
3821 return RIL_ERRNO_INVALID_RESPONSE;
3822 }
3823
3824 RIL_ActivityStatsInfo *p_cur = (RIL_ActivityStatsInfo *)response;
3825 p.writeInt32(p_cur->sleep_mode_time_ms);
3826 p.writeInt32(p_cur->idle_mode_time_ms);
3827 for(int i = 0; i < RIL_NUM_TX_POWER_LEVELS; i++) {
3828 p.writeInt32(p_cur->tx_mode_time_ms[i]);
3829 }
3830 p.writeInt32(p_cur->rx_mode_time_ms);
3831
3832 startResponse;
3833 appendPrintBuf("Modem activity info received: sleep_mode_time_ms %d idle_mode_time_ms %d
3834 tx_mode_time_ms %d %d %d %d %d and rx_mode_time_ms %d",
3835 p_cur->sleep_mode_time_ms, p_cur->idle_mode_time_ms, p_cur->tx_mode_time_ms[0],
3836 p_cur->tx_mode_time_ms[1], p_cur->tx_mode_time_ms[2], p_cur->tx_mode_time_ms[3],
3837 p_cur->tx_mode_time_ms[4], p_cur->rx_mode_time_ms);
3838 closeResponse;
3839
3840 return 0;
3841}
3842
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003843/**
3844 * A write on the wakeup fd is done just to pop us out of select()
3845 * We empty the buffer here and then ril_event will reset the timers on the
3846 * way back down
3847 */
3848static void processWakeupCallback(int fd, short flags, void *param) {
3849 char buff[16];
3850 int ret;
3851
Ethan Chend6e30652013-08-04 22:49:56 -07003852 RLOGV("processWakeupCallback");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003853
3854 /* empty our wakeup socket out */
3855 do {
3856 ret = read(s_fdWakeupRead, &buff, sizeof(buff));
3857 } while (ret > 0 || (ret < 0 && errno == EINTR));
3858}
3859
Howard Sue32dbfd2015-01-07 15:55:57 +08003860static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003861 int ret;
3862 RequestInfo *p_cur;
Howard Sue32dbfd2015-01-07 15:55:57 +08003863 /* Hook for current context
3864 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
3865 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
3866 /* pendingRequestsHook refer to &s_pendingRequests */
3867 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003868
Howard Sue32dbfd2015-01-07 15:55:57 +08003869#if (SIM_COUNT >= 2)
3870 if (socket_id == RIL_SOCKET_2) {
3871 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
3872 pendingRequestsHook = &s_pendingRequests_socket2;
3873 }
3874#if (SIM_COUNT >= 3)
3875 else if (socket_id == RIL_SOCKET_3) {
3876 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
3877 pendingRequestsHook = &s_pendingRequests_socket3;
3878 }
3879#endif
3880#if (SIM_COUNT >= 4)
3881 else if (socket_id == RIL_SOCKET_4) {
3882 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
3883 pendingRequestsHook = &s_pendingRequests_socket4;
3884 }
3885#endif
3886#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003887 /* mark pending requests as "cancelled" so we dont report responses */
Howard Sue32dbfd2015-01-07 15:55:57 +08003888 ret = pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003889 assert (ret == 0);
3890
Howard Sue32dbfd2015-01-07 15:55:57 +08003891 p_cur = *pendingRequestsHook;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003892
Howard Sue32dbfd2015-01-07 15:55:57 +08003893 for (p_cur = *pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003894 ; p_cur != NULL
3895 ; p_cur = p_cur->p_next
3896 ) {
3897 p_cur->cancelled = 1;
3898 }
3899
Howard Sue32dbfd2015-01-07 15:55:57 +08003900 ret = pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003901 assert (ret == 0);
3902}
3903
3904static void processCommandsCallback(int fd, short flags, void *param) {
3905 RecordStream *p_rs;
3906 void *p_record;
3907 size_t recordlen;
3908 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08003909 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003910
Howard Sue32dbfd2015-01-07 15:55:57 +08003911 assert(fd == p_info->fdCommand);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003912
Howard Sue32dbfd2015-01-07 15:55:57 +08003913 p_rs = p_info->p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003914
3915 for (;;) {
3916 /* loop until EAGAIN/EINTR, end of stream, or other error */
3917 ret = record_stream_get_next(p_rs, &p_record, &recordlen);
3918
3919 if (ret == 0 && p_record == NULL) {
3920 /* end-of-stream */
3921 break;
3922 } else if (ret < 0) {
3923 break;
3924 } else if (ret == 0) { /* && p_record != NULL */
Howard Sue32dbfd2015-01-07 15:55:57 +08003925 processCommandBuffer(p_record, recordlen, p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003926 }
3927 }
3928
3929 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
3930 /* fatal error or end-of-stream */
3931 if (ret != 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003932 RLOGE("error on reading command socket errno:%d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003933 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003934 RLOGW("EOS. Closing command socket.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003935 }
3936
Howard Sue32dbfd2015-01-07 15:55:57 +08003937 close(fd);
3938 p_info->fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003939
Howard Sue32dbfd2015-01-07 15:55:57 +08003940 ril_event_del(p_info->commands_event);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003941
3942 record_stream_free(p_rs);
3943
3944 /* start listening for new connections again */
3945 rilEventAddWakeup(&s_listen_event);
3946
Howard Sue32dbfd2015-01-07 15:55:57 +08003947 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003948 }
3949}
3950
Howard Subd82ef12015-04-12 10:25:05 +02003951
Howard Sue32dbfd2015-01-07 15:55:57 +08003952static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003953 // Inform we are connected and the ril version
3954 int rilVer = s_callbacks.version;
Howard Sue32dbfd2015-01-07 15:55:57 +08003955 RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
3956 &rilVer, sizeof(rilVer), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003957
3958 // implicit radio state changed
Howard Sue32dbfd2015-01-07 15:55:57 +08003959 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
3960 NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003961
3962 // Send last NITZ time data, in case it was missed
3963 if (s_lastNITZTimeData != NULL) {
Howard Sue32dbfd2015-01-07 15:55:57 +08003964 sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003965
3966 free(s_lastNITZTimeData);
3967 s_lastNITZTimeData = NULL;
3968 }
3969
3970 // Get version string
3971 if (s_callbacks.getVersion != NULL) {
3972 const char *version;
3973 version = s_callbacks.getVersion();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003974 RLOGI("RIL Daemon version: %s\n", version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003975
3976 property_set(PROPERTY_RIL_IMPL, version);
3977 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02003978 RLOGI("RIL Daemon version: unavailable\n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003979 property_set(PROPERTY_RIL_IMPL, "unavailable");
3980 }
3981
3982}
3983
3984static void listenCallback (int fd, short flags, void *param) {
3985 int ret;
3986 int err;
3987 int is_phone_socket;
Howard Sue32dbfd2015-01-07 15:55:57 +08003988 int fdCommand = -1;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003989 char* processName;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003990 RecordStream *p_rs;
Dheeraj Shettycc231012014-07-02 21:27:57 +02003991 MySocketListenParam* listenParam;
3992 RilSocket *sapSocket = NULL;
3993 socketClient *sClient = NULL;
3994
Howard Sue32dbfd2015-01-07 15:55:57 +08003995 SocketListenParam *p_info = (SocketListenParam *)param;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02003996
Dheeraj Shettycc231012014-07-02 21:27:57 +02003997 if(RIL_SAP_SOCKET == p_info->type) {
3998 listenParam = (MySocketListenParam *)param;
3999 sapSocket = listenParam->socket;
4000 }
4001
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004002 struct sockaddr_un peeraddr;
4003 socklen_t socklen = sizeof (peeraddr);
4004
4005 struct ucred creds;
4006 socklen_t szCreds = sizeof(creds);
4007
4008 struct passwd *pwd = NULL;
4009
Dheeraj Shettycc231012014-07-02 21:27:57 +02004010 if(NULL == sapSocket) {
4011 assert (*p_info->fdCommand < 0);
4012 assert (fd == *p_info->fdListen);
4013 processName = PHONE_PROCESS;
4014 } else {
4015 assert (sapSocket->commandFd < 0);
4016 assert (fd == sapSocket->listenFd);
4017 processName = BLUETOOTH_PROCESS;
4018 }
4019
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004020
Howard Sue32dbfd2015-01-07 15:55:57 +08004021 fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004022
Howard Sue32dbfd2015-01-07 15:55:57 +08004023 if (fdCommand < 0 ) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004024 RLOGE("Error on accept() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004025 /* start listening for new connections again */
Dheeraj Shettycc231012014-07-02 21:27:57 +02004026 if(NULL == sapSocket) {
4027 rilEventAddWakeup(p_info->listen_event);
4028 } else {
4029 rilEventAddWakeup(sapSocket->getListenEvent());
4030 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004031 return;
4032 }
4033
4034 /* check the credential of the other side and only accept socket from
4035 * phone process
4036 */
4037 errno = 0;
4038 is_phone_socket = 0;
4039
Howard Sue32dbfd2015-01-07 15:55:57 +08004040 err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004041
4042 if (err == 0 && szCreds > 0) {
4043 errno = 0;
4044 pwd = getpwuid(creds.uid);
4045 if (pwd != NULL) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004046 if (strcmp(pwd->pw_name, processName) == 0) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004047 is_phone_socket = 1;
4048 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004049 RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004050 }
4051 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004052 RLOGE("Error on getpwuid() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004053 }
4054 } else {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004055 RLOGD("Error on getsockopt() errno: %d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004056 }
4057
Howard Subd82ef12015-04-12 10:25:05 +02004058 if (!is_phone_socket) {
Dheeraj Shettycc231012014-07-02 21:27:57 +02004059 RLOGE("RILD must accept socket from %s", processName);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004060
Dheeraj Shettycc231012014-07-02 21:27:57 +02004061 close(fdCommand);
4062 fdCommand = -1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004063
Dheeraj Shettycc231012014-07-02 21:27:57 +02004064 if(NULL == sapSocket) {
4065 onCommandsSocketClosed(p_info->socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004066
Dheeraj Shettycc231012014-07-02 21:27:57 +02004067 /* start listening for new connections again */
4068 rilEventAddWakeup(p_info->listen_event);
4069 } else {
4070 sapSocket->onCommandsSocketClosed();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004071
Dheeraj Shettycc231012014-07-02 21:27:57 +02004072 /* start listening for new connections again */
4073 rilEventAddWakeup(sapSocket->getListenEvent());
4074 }
4075
4076 return;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004077 }
4078
Howard Sue32dbfd2015-01-07 15:55:57 +08004079 ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004080
4081 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004082 RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004083 }
4084
Dheeraj Shettycc231012014-07-02 21:27:57 +02004085 if(NULL == sapSocket) {
4086 RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004087
Dheeraj Shettycc231012014-07-02 21:27:57 +02004088 p_info->fdCommand = fdCommand;
4089 p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
4090 p_info->p_rs = p_rs;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004091
Dheeraj Shettycc231012014-07-02 21:27:57 +02004092 ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
Howard Sue32dbfd2015-01-07 15:55:57 +08004093 p_info->processCommandsCallback, p_info);
Dheeraj Shettycc231012014-07-02 21:27:57 +02004094 rilEventAddWakeup (p_info->commands_event);
Howard Sue32dbfd2015-01-07 15:55:57 +08004095
Dheeraj Shettycc231012014-07-02 21:27:57 +02004096 onNewCommandConnect(p_info->socket_id);
4097 } else {
4098 RLOGI("libril: new connection");
Howard Sue32dbfd2015-01-07 15:55:57 +08004099
Dheeraj Shettycc231012014-07-02 21:27:57 +02004100 sapSocket->setCommandFd(fdCommand);
4101 p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
4102 sClient = new socketClient(sapSocket,p_rs);
4103 ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
4104 sapSocket->getCommandCb(), sClient);
4105
4106 rilEventAddWakeup(sapSocket->getCallbackEvent());
4107 sapSocket->onNewCommandConnect();
4108 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004109}
4110
4111static void freeDebugCallbackArgs(int number, char **args) {
4112 for (int i = 0; i < number; i++) {
4113 if (args[i] != NULL) {
4114 free(args[i]);
4115 }
4116 }
4117 free(args);
4118}
4119
4120static void debugCallback (int fd, short flags, void *param) {
4121 int acceptFD, option;
4122 struct sockaddr_un peeraddr;
4123 socklen_t socklen = sizeof (peeraddr);
4124 int data;
4125 unsigned int qxdm_data[6];
4126 const char *deactData[1] = {"1"};
4127 char *actData[1];
4128 RIL_Dial dialData;
4129 int hangupData[1] = {1};
4130 int number;
4131 char **args;
Howard Sue32dbfd2015-01-07 15:55:57 +08004132 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
4133 int sim_id = 0;
4134
4135 RLOGI("debugCallback for socket %s", rilSocketIdToString(socket_id));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004136
4137 acceptFD = accept (fd, (sockaddr *) &peeraddr, &socklen);
4138
4139 if (acceptFD < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004140 RLOGE ("error accepting on debug port: %d\n", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004141 return;
4142 }
4143
4144 if (recv(acceptFD, &number, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004145 RLOGE ("error reading on socket: number of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004146 return;
4147 }
4148 args = (char **) malloc(sizeof(char*) * number);
4149
4150 for (int i = 0; i < number; i++) {
4151 int len;
4152 if (recv(acceptFD, &len, sizeof(int), 0) != sizeof(int)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004153 RLOGE ("error reading on socket: Len of Args: \n");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004154 freeDebugCallbackArgs(i, args);
4155 return;
4156 }
4157 // +1 for null-term
4158 args[i] = (char *) malloc((sizeof(char) * len) + 1);
4159 if (recv(acceptFD, args[i], sizeof(char) * len, 0)
4160 != (int)sizeof(char) * len) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004161 RLOGE ("error reading on socket: Args[%d] \n", i);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004162 freeDebugCallbackArgs(i, args);
4163 return;
4164 }
4165 char * buf = args[i];
4166 buf[len] = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004167 if ((i+1) == number) {
4168 /* The last argument should be sim id 0(SIM1)~3(SIM4) */
4169 sim_id = atoi(args[i]);
4170 switch (sim_id) {
4171 case 0:
4172 socket_id = RIL_SOCKET_1;
4173 break;
4174 #if (SIM_COUNT >= 2)
4175 case 1:
4176 socket_id = RIL_SOCKET_2;
4177 break;
4178 #endif
4179 #if (SIM_COUNT >= 3)
4180 case 2:
4181 socket_id = RIL_SOCKET_3;
4182 break;
4183 #endif
4184 #if (SIM_COUNT >= 4)
4185 case 3:
4186 socket_id = RIL_SOCKET_4;
4187 break;
4188 #endif
4189 default:
4190 socket_id = RIL_SOCKET_1;
4191 break;
4192 }
4193 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004194 }
4195
4196 switch (atoi(args[0])) {
4197 case 0:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004198 RLOGI ("Connection on debug port: issuing reset.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004199 issueLocalRequest(RIL_REQUEST_RESET_RADIO, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004200 break;
4201 case 1:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004202 RLOGI ("Connection on debug port: issuing radio power off.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004203 data = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004204 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004205 // Close the socket
Howard Subd82ef12015-04-12 10:25:05 +02004206 if (socket_id == RIL_SOCKET_1 && s_ril_param_socket.fdCommand > 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004207 close(s_ril_param_socket.fdCommand);
4208 s_ril_param_socket.fdCommand = -1;
4209 }
4210 #if (SIM_COUNT == 2)
4211 else if (socket_id == RIL_SOCKET_2 && s_ril_param_socket2.fdCommand > 0) {
4212 close(s_ril_param_socket2.fdCommand);
4213 s_ril_param_socket2.fdCommand = -1;
4214 }
4215 #endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004216 break;
4217 case 2:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004218 RLOGI ("Debug port: issuing unsolicited voice network change.");
Howard Sue32dbfd2015-01-07 15:55:57 +08004219 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004220 break;
4221 case 3:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004222 RLOGI ("Debug port: QXDM log enable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004223 qxdm_data[0] = 65536; // head.func_tag
4224 qxdm_data[1] = 16; // head.len
4225 qxdm_data[2] = 1; // mode: 1 for 'start logging'
4226 qxdm_data[3] = 32; // log_file_size: 32megabytes
4227 qxdm_data[4] = 0; // log_mask
4228 qxdm_data[5] = 8; // log_max_fileindex
4229 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004230 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004231 break;
4232 case 4:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004233 RLOGI ("Debug port: QXDM log disable.");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004234 qxdm_data[0] = 65536;
4235 qxdm_data[1] = 16;
4236 qxdm_data[2] = 0; // mode: 0 for 'stop logging'
4237 qxdm_data[3] = 32;
4238 qxdm_data[4] = 0;
4239 qxdm_data[5] = 8;
4240 issueLocalRequest(RIL_REQUEST_OEM_HOOK_RAW, qxdm_data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004241 6 * sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004242 break;
4243 case 5:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004244 RLOGI("Debug port: Radio On");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004245 data = 1;
Howard Sue32dbfd2015-01-07 15:55:57 +08004246 issueLocalRequest(RIL_REQUEST_RADIO_POWER, &data, sizeof(int), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004247 sleep(2);
4248 // Set network selection automatic.
Howard Sue32dbfd2015-01-07 15:55:57 +08004249 issueLocalRequest(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004250 break;
4251 case 6:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004252 RLOGI("Debug port: Setup Data Call, Apn :%s\n", args[1]);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004253 actData[0] = args[1];
4254 issueLocalRequest(RIL_REQUEST_SETUP_DATA_CALL, &actData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004255 sizeof(actData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004256 break;
4257 case 7:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004258 RLOGI("Debug port: Deactivate Data Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004259 issueLocalRequest(RIL_REQUEST_DEACTIVATE_DATA_CALL, &deactData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004260 sizeof(deactData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004261 break;
4262 case 8:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004263 RLOGI("Debug port: Dial Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004264 dialData.clir = 0;
4265 dialData.address = args[1];
Howard Sue32dbfd2015-01-07 15:55:57 +08004266 issueLocalRequest(RIL_REQUEST_DIAL, &dialData, sizeof(dialData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004267 break;
4268 case 9:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004269 RLOGI("Debug port: Answer Call");
Howard Sue32dbfd2015-01-07 15:55:57 +08004270 issueLocalRequest(RIL_REQUEST_ANSWER, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004271 break;
4272 case 10:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004273 RLOGI("Debug port: End Call");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004274 issueLocalRequest(RIL_REQUEST_HANGUP, &hangupData,
Howard Sue32dbfd2015-01-07 15:55:57 +08004275 sizeof(hangupData), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004276 break;
4277 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004278 RLOGE ("Invalid request");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004279 break;
4280 }
4281 freeDebugCallbackArgs(number, args);
4282 close(acceptFD);
4283}
4284
4285
4286static void userTimerCallback (int fd, short flags, void *param) {
4287 UserCallbackInfo *p_info;
4288
4289 p_info = (UserCallbackInfo *)param;
4290
4291 p_info->p_callback(p_info->userParam);
4292
4293
4294 // FIXME generalize this...there should be a cancel mechanism
4295 if (s_last_wake_timeout_info != NULL && s_last_wake_timeout_info == p_info) {
4296 s_last_wake_timeout_info = NULL;
4297 }
4298
4299 free(p_info);
4300}
4301
4302
4303static void *
4304eventLoop(void *param) {
4305 int ret;
4306 int filedes[2];
4307
4308 ril_event_init();
4309
4310 pthread_mutex_lock(&s_startupMutex);
4311
4312 s_started = 1;
4313 pthread_cond_broadcast(&s_startupCond);
4314
4315 pthread_mutex_unlock(&s_startupMutex);
4316
4317 ret = pipe(filedes);
4318
4319 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004320 RLOGE("Error in pipe() errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004321 return NULL;
4322 }
4323
4324 s_fdWakeupRead = filedes[0];
4325 s_fdWakeupWrite = filedes[1];
4326
4327 fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);
4328
4329 ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
4330 processWakeupCallback, NULL);
4331
4332 rilEventAddWakeup (&s_wakeupfd_event);
4333
4334 // Only returns on error
4335 ril_event_loop();
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004336 RLOGE ("error in event_loop_base errno:%d", errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004337 // kill self to restart on error
4338 kill(0, SIGKILL);
4339
4340 return NULL;
4341}
4342
4343extern "C" void
4344RIL_startEventLoop(void) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004345 /* spin up eventLoop thread and wait for it to get started */
4346 s_started = 0;
4347 pthread_mutex_lock(&s_startupMutex);
4348
Howard Sue32dbfd2015-01-07 15:55:57 +08004349 pthread_attr_t attr;
4350 pthread_attr_init(&attr);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004351 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Howard Sue32dbfd2015-01-07 15:55:57 +08004352
4353 int result = pthread_create(&s_tid_dispatch, &attr, eventLoop, NULL);
4354 if (result != 0) {
4355 RLOGE("Failed to create dispatch thread: %s", strerror(result));
4356 goto done;
4357 }
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004358
4359 while (s_started == 0) {
4360 pthread_cond_wait(&s_startupCond, &s_startupMutex);
4361 }
4362
Howard Sue32dbfd2015-01-07 15:55:57 +08004363done:
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004364 pthread_mutex_unlock(&s_startupMutex);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004365}
4366
4367// Used for testing purpose only.
4368extern "C" void RIL_setcallbacks (const RIL_RadioFunctions *callbacks) {
4369 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4370}
4371
Howard Sue32dbfd2015-01-07 15:55:57 +08004372static void startListen(RIL_SOCKET_ID socket_id, SocketListenParam* socket_listen_p) {
4373 int fdListen = -1;
4374 int ret;
4375 char socket_name[10];
4376
4377 memset(socket_name, 0, sizeof(char)*10);
4378
4379 switch(socket_id) {
4380 case RIL_SOCKET_1:
4381 strncpy(socket_name, RIL_getRilSocketName(), 9);
4382 break;
4383 #if (SIM_COUNT >= 2)
4384 case RIL_SOCKET_2:
4385 strncpy(socket_name, SOCKET2_NAME_RIL, 9);
4386 break;
4387 #endif
4388 #if (SIM_COUNT >= 3)
4389 case RIL_SOCKET_3:
4390 strncpy(socket_name, SOCKET3_NAME_RIL, 9);
4391 break;
4392 #endif
4393 #if (SIM_COUNT >= 4)
4394 case RIL_SOCKET_4:
4395 strncpy(socket_name, SOCKET4_NAME_RIL, 9);
4396 break;
4397 #endif
4398 default:
4399 RLOGE("Socket id is wrong!!");
4400 return;
4401 }
4402
4403 RLOGI("Start to listen %s", rilSocketIdToString(socket_id));
4404
4405 fdListen = android_get_control_socket(socket_name);
4406 if (fdListen < 0) {
4407 RLOGE("Failed to get socket %s", socket_name);
4408 exit(-1);
4409 }
4410
4411 ret = listen(fdListen, 4);
4412
4413 if (ret < 0) {
4414 RLOGE("Failed to listen on control socket '%d': %s",
4415 fdListen, strerror(errno));
4416 exit(-1);
4417 }
4418 socket_listen_p->fdListen = fdListen;
4419
4420 /* note: non-persistent so we can accept only one connection at a time */
4421 ril_event_set (socket_listen_p->listen_event, fdListen, false,
4422 listenCallback, socket_listen_p);
4423
4424 rilEventAddWakeup (socket_listen_p->listen_event);
4425}
4426
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004427extern "C" void
4428RIL_register (const RIL_RadioFunctions *callbacks) {
4429 int ret;
4430 int flags;
4431
Howard Sue32dbfd2015-01-07 15:55:57 +08004432 RLOGI("SIM_COUNT: %d", SIM_COUNT);
4433
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004434 if (callbacks == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004435 RLOGE("RIL_register: RIL_RadioFunctions * null");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004436 return;
4437 }
4438 if (callbacks->version < RIL_VERSION_MIN) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004439 RLOGE("RIL_register: version %d is to old, min version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004440 callbacks->version, RIL_VERSION_MIN);
4441 return;
4442 }
4443 if (callbacks->version > RIL_VERSION) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004444 RLOGE("RIL_register: version %d is too new, max version is %d",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004445 callbacks->version, RIL_VERSION);
4446 return;
4447 }
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004448 RLOGE("RIL_register: RIL version %d", callbacks->version);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004449
4450 if (s_registerCalled > 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004451 RLOGE("RIL_register has been called more than once. "
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004452 "Subsequent call ignored");
4453 return;
4454 }
4455
4456 memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));
4457
Howard Sue32dbfd2015-01-07 15:55:57 +08004458 /* Initialize socket1 parameters */
4459 s_ril_param_socket = {
4460 RIL_SOCKET_1, /* socket_id */
4461 -1, /* fdListen */
4462 -1, /* fdCommand */
4463 PHONE_PROCESS, /* processName */
4464 &s_commands_event, /* commands_event */
4465 &s_listen_event, /* listen_event */
4466 processCommandsCallback, /* processCommandsCallback */
4467 NULL /* p_rs */
4468 };
4469
4470#if (SIM_COUNT >= 2)
4471 s_ril_param_socket2 = {
4472 RIL_SOCKET_2, /* socket_id */
4473 -1, /* fdListen */
4474 -1, /* fdCommand */
4475 PHONE_PROCESS, /* processName */
4476 &s_commands_event_socket2, /* commands_event */
4477 &s_listen_event_socket2, /* listen_event */
4478 processCommandsCallback, /* processCommandsCallback */
4479 NULL /* p_rs */
4480 };
4481#endif
4482
4483#if (SIM_COUNT >= 3)
4484 s_ril_param_socket3 = {
4485 RIL_SOCKET_3, /* socket_id */
4486 -1, /* fdListen */
4487 -1, /* fdCommand */
4488 PHONE_PROCESS, /* processName */
4489 &s_commands_event_socket3, /* commands_event */
4490 &s_listen_event_socket3, /* listen_event */
4491 processCommandsCallback, /* processCommandsCallback */
4492 NULL /* p_rs */
4493 };
4494#endif
4495
4496#if (SIM_COUNT >= 4)
4497 s_ril_param_socket4 = {
4498 RIL_SOCKET_4, /* socket_id */
4499 -1, /* fdListen */
4500 -1, /* fdCommand */
4501 PHONE_PROCESS, /* processName */
4502 &s_commands_event_socket4, /* commands_event */
4503 &s_listen_event_socket4, /* listen_event */
4504 processCommandsCallback, /* processCommandsCallback */
4505 NULL /* p_rs */
4506 };
4507#endif
4508
Howard Subd82ef12015-04-12 10:25:05 +02004509
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004510 s_registerCalled = 1;
4511
Howard Sue32dbfd2015-01-07 15:55:57 +08004512 RLOGI("s_registerCalled flag set, %d", s_started);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004513 // Little self-check
4514
4515 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
4516 assert(i == s_commands[i].requestNumber);
4517 }
4518
Howard Subd82ef12015-04-12 10:25:05 +02004519 for (int i = 0; i < (int)NUM_ELEMS(s_commands_v); i++) {
4520 assert(i + RIL_VENDOR_COMMANDS_OFFSET == s_commands[i].requestNumber);
4521 }
4522
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004523 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004524 assert(i + RIL_UNSOL_RESPONSE_BASE
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004525 == s_unsolResponses[i].requestNumber);
4526 }
4527
Howard Subd82ef12015-04-12 10:25:05 +02004528 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses_v); i++) {
4529 assert(i + RIL_UNSOL_RESPONSE_BASE + RIL_VENDOR_COMMANDS_OFFSET
4530 == s_unsolResponses[i].requestNumber);
4531 }
4532
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004533 // New rild impl calls RIL_startEventLoop() first
4534 // old standalone impl wants it here.
4535
4536 if (s_started == 0) {
4537 RIL_startEventLoop();
4538 }
4539
Howard Sue32dbfd2015-01-07 15:55:57 +08004540 // start listen socket1
4541 startListen(RIL_SOCKET_1, &s_ril_param_socket);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004542
Howard Sue32dbfd2015-01-07 15:55:57 +08004543#if (SIM_COUNT >= 2)
4544 // start listen socket2
4545 startListen(RIL_SOCKET_2, &s_ril_param_socket2);
4546#endif /* (SIM_COUNT == 2) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004547
Howard Sue32dbfd2015-01-07 15:55:57 +08004548#if (SIM_COUNT >= 3)
4549 // start listen socket3
4550 startListen(RIL_SOCKET_3, &s_ril_param_socket3);
4551#endif /* (SIM_COUNT == 3) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004552
Howard Sue32dbfd2015-01-07 15:55:57 +08004553#if (SIM_COUNT >= 4)
4554 // start listen socket4
4555 startListen(RIL_SOCKET_4, &s_ril_param_socket4);
4556#endif /* (SIM_COUNT == 4) */
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004557
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004558
4559#if 1
4560 // start debug interface socket
4561
Howard Sue32dbfd2015-01-07 15:55:57 +08004562 char *inst = NULL;
4563 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
4564 inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
4565 }
4566
4567 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
4568 if (inst != NULL) {
Andreas Schneider3063dc12015-04-13 23:04:05 +02004569 snprintf(rildebug, sizeof(rildebug), "%s%s", SOCKET_NAME_RIL_DEBUG, inst);
Howard Sue32dbfd2015-01-07 15:55:57 +08004570 }
4571
4572 s_fdDebug = android_get_control_socket(rildebug);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004573 if (s_fdDebug < 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004574 RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004575 exit(-1);
4576 }
4577
4578 ret = listen(s_fdDebug, 4);
4579
4580 if (ret < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004581 RLOGE("Failed to listen on ril debug socket '%d': %s",
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004582 s_fdDebug, strerror(errno));
4583 exit(-1);
4584 }
4585
4586 ril_event_set (&s_debug_event, s_fdDebug, true,
4587 debugCallback, NULL);
4588
4589 rilEventAddWakeup (&s_debug_event);
4590#endif
4591
4592}
4593
Dheeraj Shettycc231012014-07-02 21:27:57 +02004594extern "C" void
4595RIL_register_socket (RIL_RadioFunctions *(*Init)(const struct RIL_Env *, int, char **),RIL_SOCKET_TYPE socketType, int argc, char **argv) {
4596
4597 RIL_RadioFunctions* UimFuncs = NULL;
4598
4599 if(Init) {
4600 UimFuncs = Init(&RilSapSocket::uimRilEnv, argc, argv);
4601
4602 switch(socketType) {
4603 case RIL_SAP_SOCKET:
4604 RilSapSocket::initSapSocket("sap_uim_socket1", UimFuncs);
4605
4606#if (SIM_COUNT >= 2)
4607 RilSapSocket::initSapSocket("sap_uim_socket2", UimFuncs);
4608#endif
4609
4610#if (SIM_COUNT >= 3)
4611 RilSapSocket::initSapSocket("sap_uim_socket3", UimFuncs);
4612#endif
4613
4614#if (SIM_COUNT >= 4)
4615 RilSapSocket::initSapSocket("sap_uim_socket4", UimFuncs);
4616#endif
4617 }
4618 }
4619}
4620
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004621static int
4622checkAndDequeueRequestInfo(struct RequestInfo *pRI) {
4623 int ret = 0;
Howard Sue32dbfd2015-01-07 15:55:57 +08004624 /* Hook for current context
4625 pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
4626 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
4627 /* pendingRequestsHook refer to &s_pendingRequests */
4628 RequestInfo ** pendingRequestsHook = &s_pendingRequests;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004629
4630 if (pRI == NULL) {
4631 return 0;
4632 }
4633
Howard Sue32dbfd2015-01-07 15:55:57 +08004634#if (SIM_COUNT >= 2)
4635 if (pRI->socket_id == RIL_SOCKET_2) {
4636 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
4637 pendingRequestsHook = &s_pendingRequests_socket2;
4638 }
4639#if (SIM_COUNT >= 3)
4640 if (pRI->socket_id == RIL_SOCKET_3) {
4641 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
4642 pendingRequestsHook = &s_pendingRequests_socket3;
4643 }
4644#endif
4645#if (SIM_COUNT >= 4)
4646 if (pRI->socket_id == RIL_SOCKET_4) {
4647 pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
4648 pendingRequestsHook = &s_pendingRequests_socket4;
4649 }
4650#endif
4651#endif
4652 pthread_mutex_lock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004653
Howard Sue32dbfd2015-01-07 15:55:57 +08004654 for(RequestInfo **ppCur = pendingRequestsHook
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004655 ; *ppCur != NULL
4656 ; ppCur = &((*ppCur)->p_next)
4657 ) {
4658 if (pRI == *ppCur) {
4659 ret = 1;
4660
4661 *ppCur = (*ppCur)->p_next;
4662 break;
4663 }
4664 }
4665
Howard Sue32dbfd2015-01-07 15:55:57 +08004666 pthread_mutex_unlock(pendingRequestsMutexHook);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004667
4668 return ret;
4669}
4670
4671
4672extern "C" void
4673RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
4674 RequestInfo *pRI;
4675 int ret;
Howard Sue32dbfd2015-01-07 15:55:57 +08004676 int fd = s_ril_param_socket.fdCommand;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004677 size_t errorOffset;
Howard Sue32dbfd2015-01-07 15:55:57 +08004678 RIL_SOCKET_ID socket_id = RIL_SOCKET_1;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004679
4680 pRI = (RequestInfo *)t;
4681
4682 if (!checkAndDequeueRequestInfo(pRI)) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004683 RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004684 return;
4685 }
4686
Howard Sue32dbfd2015-01-07 15:55:57 +08004687 socket_id = pRI->socket_id;
4688#if (SIM_COUNT >= 2)
4689 if (socket_id == RIL_SOCKET_2) {
4690 fd = s_ril_param_socket2.fdCommand;
4691 }
4692#if (SIM_COUNT >= 3)
4693 if (socket_id == RIL_SOCKET_3) {
4694 fd = s_ril_param_socket3.fdCommand;
4695 }
4696#endif
4697#if (SIM_COUNT >= 4)
4698 if (socket_id == RIL_SOCKET_4) {
4699 fd = s_ril_param_socket4.fdCommand;
4700 }
4701#endif
4702#endif
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004703#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08004704 RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004705#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08004706
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004707 if (pRI->local > 0) {
4708 // Locally issued command...void only!
4709 // response does not go back up the command socket
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004710 RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004711
4712 goto done;
4713 }
4714
4715 appendPrintBuf("[%04d]< %s",
4716 pRI->token, requestToString(pRI->pCI->requestNumber));
4717
4718 if (pRI->cancelled == 0) {
4719 Parcel p;
4720
4721 p.writeInt32 (RESPONSE_SOLICITED);
4722 p.writeInt32 (pRI->token);
4723 errorOffset = p.dataPosition();
4724
4725 p.writeInt32 (e);
4726
4727 if (response != NULL) {
4728 // there is a response payload, no matter success or not.
4729 ret = pRI->pCI->responseFunction(p, response, responselen);
4730
4731 /* if an error occurred, rewind and mark it */
4732 if (ret != 0) {
Howard Sue32dbfd2015-01-07 15:55:57 +08004733 RLOGE ("responseFunction error, ret %d", ret);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004734 p.setDataPosition(errorOffset);
4735 p.writeInt32 (ret);
4736 }
4737 }
4738
4739 if (e != RIL_E_SUCCESS) {
4740 appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
4741 }
4742
Howard Sue32dbfd2015-01-07 15:55:57 +08004743 if (fd < 0) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004744 RLOGD ("RIL onRequestComplete: Command channel closed");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004745 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004746 sendResponse(p, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004747 }
4748
4749done:
4750 free(pRI);
4751}
4752
Howard Subd82ef12015-04-12 10:25:05 +02004753
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004754static void
4755grabPartialWakeLock() {
4756 acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
4757}
4758
4759static void
4760releaseWakeLock() {
4761 release_wake_lock(ANDROID_WAKE_LOCK_NAME);
4762}
4763
4764/**
4765 * Timer callback to put us back to sleep before the default timeout
4766 */
4767static void
4768wakeTimeoutCallback (void *param) {
4769 // We're using "param != NULL" as a cancellation mechanism
4770 if (param == NULL) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004771 releaseWakeLock();
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004772 }
4773}
4774
4775static int
4776decodeVoiceRadioTechnology (RIL_RadioState radioState) {
4777 switch (radioState) {
4778 case RADIO_STATE_SIM_NOT_READY:
4779 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4780 case RADIO_STATE_SIM_READY:
4781 return RADIO_TECH_UMTS;
4782
4783 case RADIO_STATE_RUIM_NOT_READY:
4784 case RADIO_STATE_RUIM_READY:
4785 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4786 case RADIO_STATE_NV_NOT_READY:
4787 case RADIO_STATE_NV_READY:
4788 return RADIO_TECH_1xRTT;
4789
4790 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004791 RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004792 return -1;
4793 }
4794}
4795
4796static int
4797decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
4798 switch (radioState) {
4799 case RADIO_STATE_SIM_NOT_READY:
4800 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4801 case RADIO_STATE_SIM_READY:
4802 case RADIO_STATE_RUIM_NOT_READY:
4803 case RADIO_STATE_RUIM_READY:
4804 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4805 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;
4806
4807 case RADIO_STATE_NV_NOT_READY:
4808 case RADIO_STATE_NV_READY:
4809 return CDMA_SUBSCRIPTION_SOURCE_NV;
4810
4811 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004812 RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004813 return -1;
4814 }
4815}
4816
4817static int
4818decodeSimStatus (RIL_RadioState radioState) {
4819 switch (radioState) {
4820 case RADIO_STATE_SIM_NOT_READY:
4821 case RADIO_STATE_RUIM_NOT_READY:
4822 case RADIO_STATE_NV_NOT_READY:
4823 case RADIO_STATE_NV_READY:
4824 return -1;
4825 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
4826 case RADIO_STATE_SIM_READY:
4827 case RADIO_STATE_RUIM_READY:
4828 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
4829 return radioState;
4830 default:
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004831 RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004832 return -1;
4833 }
4834}
4835
4836static bool is3gpp2(int radioTech) {
4837 switch (radioTech) {
4838 case RADIO_TECH_IS95A:
4839 case RADIO_TECH_IS95B:
4840 case RADIO_TECH_1xRTT:
4841 case RADIO_TECH_EVDO_0:
4842 case RADIO_TECH_EVDO_A:
4843 case RADIO_TECH_EVDO_B:
4844 case RADIO_TECH_EHRPD:
4845 return true;
4846 default:
4847 return false;
4848 }
4849}
4850
4851/* If RIL sends SIM states or RUIM states, store the voice radio
4852 * technology and subscription source information so that they can be
4853 * returned when telephony framework requests them
4854 */
4855static RIL_RadioState
Howard Subd82ef12015-04-12 10:25:05 +02004856processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004857
4858 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
4859 int newVoiceRadioTech;
4860 int newCdmaSubscriptionSource;
4861 int newSimStatus;
4862
4863 /* This is old RIL. Decode Subscription source and Voice Radio Technology
4864 from Radio State and send change notifications if there has been a change */
4865 newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
4866 if(newVoiceRadioTech != voiceRadioTech) {
4867 voiceRadioTech = newVoiceRadioTech;
Howard Sue32dbfd2015-01-07 15:55:57 +08004868 RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
4869 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004870 }
4871 if(is3gpp2(newVoiceRadioTech)) {
4872 newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
4873 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
4874 cdmaSubscriptionSource = newCdmaSubscriptionSource;
Howard Sue32dbfd2015-01-07 15:55:57 +08004875 RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
4876 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004877 }
4878 }
4879 newSimStatus = decodeSimStatus(newRadioState);
4880 if(newSimStatus != simRuimStatus) {
4881 simRuimStatus = newSimStatus;
Howard Sue32dbfd2015-01-07 15:55:57 +08004882 RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004883 }
4884
4885 /* Send RADIO_ON to telephony */
4886 newRadioState = RADIO_STATE_ON;
4887 }
4888
4889 return newRadioState;
4890}
4891
Howard Subd82ef12015-04-12 10:25:05 +02004892
Howard Sue32dbfd2015-01-07 15:55:57 +08004893#if defined(ANDROID_MULTI_SIM)
4894extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004895void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Howard Sue32dbfd2015-01-07 15:55:57 +08004896 size_t datalen, RIL_SOCKET_ID socket_id)
4897#else
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004898extern "C"
Andreas Schneider47b2d962015-04-13 22:54:49 +02004899void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004900 size_t datalen)
Howard Sue32dbfd2015-01-07 15:55:57 +08004901#endif
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004902{
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004903 int ret;
4904 int64_t timeReceived = 0;
4905 bool shouldScheduleTimeout = false;
4906 RIL_RadioState newState;
Howard Sue32dbfd2015-01-07 15:55:57 +08004907 RIL_SOCKET_ID soc_id = RIL_SOCKET_1;
Howard Subd82ef12015-04-12 10:25:05 +02004908 UnsolResponseInfo *pRI = NULL;
Howard Sue32dbfd2015-01-07 15:55:57 +08004909
4910#if defined(ANDROID_MULTI_SIM)
4911 soc_id = socket_id;
4912#endif
4913
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004914
4915 if (s_registerCalled == 0) {
4916 // Ignore RIL_onUnsolicitedResponse before RIL_register
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004917 RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004918 return;
4919 }
Howard Sue32dbfd2015-01-07 15:55:57 +08004920
Howard Subd82ef12015-04-12 10:25:05 +02004921 /* Hack to include Samsung responses */
4922 if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) {
4923 int index = unsolResponse - RIL_VENDOR_COMMANDS_OFFSET - RIL_UNSOL_RESPONSE_BASE;
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004924
Howard Subd82ef12015-04-12 10:25:05 +02004925 RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, index);
4926
4927 if (index < (int32_t)NUM_ELEMS(s_unsolResponses_v))
4928 pRI = &s_unsolResponses_v[index];
4929 } else {
4930 int index = unsolResponse - RIL_UNSOL_RESPONSE_BASE;
4931 if (index < (int32_t)NUM_ELEMS(s_unsolResponses))
4932 pRI = &s_unsolResponses[index];
4933 }
4934
4935 if (pRI == NULL || pRI->responseFunction == NULL) {
XpLoDWilDba5c6a32013-07-27 21:12:19 +02004936 RLOGE("unsupported unsolicited response code %d", unsolResponse);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004937 return;
4938 }
4939
4940 // Grab a wake lock if needed for this reponse,
4941 // as we exit we'll either release it immediately
4942 // or set a timer to release it later.
Howard Subd82ef12015-04-12 10:25:05 +02004943 switch (pRI->wakeType) {
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004944 case WAKE_PARTIAL:
4945 grabPartialWakeLock();
4946 shouldScheduleTimeout = true;
4947 break;
4948
4949 case DONT_WAKE:
4950 default:
4951 // No wake lock is grabed so don't set timeout
4952 shouldScheduleTimeout = false;
4953 break;
4954 }
4955
4956 // Mark the time this was received, doing this
4957 // after grabing the wakelock incase getting
4958 // the elapsedRealTime might cause us to goto
4959 // sleep.
4960 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
4961 timeReceived = elapsedRealtime();
4962 }
4963
4964 appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));
4965
4966 Parcel p;
4967
4968 p.writeInt32 (RESPONSE_UNSOLICITED);
4969 p.writeInt32 (unsolResponse);
4970
Howard Subd82ef12015-04-12 10:25:05 +02004971 ret = pRI->responseFunction(p, const_cast<void*>(data), datalen);
4972
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004973 if (ret != 0) {
4974 // Problem with the response. Don't continue;
4975 goto error_exit;
4976 }
4977
4978 // some things get more payload
4979 switch(unsolResponse) {
4980 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
Howard Sue32dbfd2015-01-07 15:55:57 +08004981 newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004982 p.writeInt32(newState);
4983 appendPrintBuf("%s {%s}", printBuf,
Howard Sue32dbfd2015-01-07 15:55:57 +08004984 radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02004985 break;
4986
4987
4988 case RIL_UNSOL_NITZ_TIME_RECEIVED:
4989 // Store the time that this was received so the
4990 // handler of this message can account for
4991 // the time it takes to arrive and process. In
4992 // particular the system has been known to sleep
4993 // before this message can be processed.
4994 p.writeInt64(timeReceived);
4995 break;
4996 }
4997
Robert Greenwaltbc29c432015-04-29 16:57:39 -07004998#if VDBG
Howard Sue32dbfd2015-01-07 15:55:57 +08004999 RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
Robert Greenwaltbc29c432015-04-29 16:57:39 -07005000#endif
Howard Sue32dbfd2015-01-07 15:55:57 +08005001 ret = sendResponse(p, soc_id);
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005002 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
5003
5004 // Unfortunately, NITZ time is not poll/update like everything
5005 // else in the system. So, if the upstream client isn't connected,
5006 // keep a copy of the last NITZ response (with receive time noted
5007 // above) around so we can deliver it when it is connected
5008
5009 if (s_lastNITZTimeData != NULL) {
5010 free (s_lastNITZTimeData);
5011 s_lastNITZTimeData = NULL;
5012 }
5013
5014 s_lastNITZTimeData = malloc(p.dataSize());
5015 s_lastNITZTimeDataSize = p.dataSize();
5016 memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
5017 }
5018
5019 // For now, we automatically go back to sleep after TIMEVAL_WAKE_TIMEOUT
5020 // FIXME The java code should handshake here to release wake lock
5021
5022 if (shouldScheduleTimeout) {
5023 // Cancel the previous request
5024 if (s_last_wake_timeout_info != NULL) {
5025 s_last_wake_timeout_info->userParam = (void *)1;
5026 }
5027
5028 s_last_wake_timeout_info
5029 = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
5030 &TIMEVAL_WAKE_TIMEOUT);
5031 }
5032
5033 // Normal exit
5034 return;
5035
5036error_exit:
5037 if (shouldScheduleTimeout) {
5038 releaseWakeLock();
5039 }
5040}
5041
5042/** FIXME generalize this if you track UserCAllbackInfo, clear it
5043 when the callback occurs
5044*/
5045static UserCallbackInfo *
5046internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
5047 const struct timeval *relativeTime)
5048{
5049 struct timeval myRelativeTime;
5050 UserCallbackInfo *p_info;
5051
5052 p_info = (UserCallbackInfo *) malloc (sizeof(UserCallbackInfo));
5053
5054 p_info->p_callback = callback;
5055 p_info->userParam = param;
5056
5057 if (relativeTime == NULL) {
5058 /* treat null parameter as a 0 relative time */
5059 memset (&myRelativeTime, 0, sizeof(myRelativeTime));
5060 } else {
5061 /* FIXME I think event_add's tv param is really const anyway */
5062 memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
5063 }
5064
5065 ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);
5066
5067 ril_timer_add(&(p_info->event), &myRelativeTime);
5068
5069 triggerEvLoop();
5070 return p_info;
5071}
5072
5073
5074extern "C" void
5075RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
5076 const struct timeval *relativeTime) {
5077 internalRequestTimedCallback (callback, param, relativeTime);
5078}
5079
5080const char *
5081failCauseToString(RIL_Errno e) {
5082 switch(e) {
5083 case RIL_E_SUCCESS: return "E_SUCCESS";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005084 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005085 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
5086 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
5087 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
5088 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
5089 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
5090 case RIL_E_CANCELLED: return "E_CANCELLED";
5091 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
5092 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
5093 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
5094 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
5095 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
5096#ifdef FEATURE_MULTIMODE_ANDROID
5097 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
5098 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
5099#endif
5100 default: return "<unknown error>";
5101 }
5102}
5103
5104const char *
5105radioStateToString(RIL_RadioState s) {
5106 switch(s) {
5107 case RADIO_STATE_OFF: return "RADIO_OFF";
5108 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
5109 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
5110 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
5111 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
5112 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
5113 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
5114 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
5115 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
5116 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
5117 case RADIO_STATE_ON:return"RADIO_ON";
5118 default: return "<unknown state>";
5119 }
5120}
5121
5122const char *
5123callStateToString(RIL_CallState s) {
5124 switch(s) {
5125 case RIL_CALL_ACTIVE : return "ACTIVE";
5126 case RIL_CALL_HOLDING: return "HOLDING";
5127 case RIL_CALL_DIALING: return "DIALING";
5128 case RIL_CALL_ALERTING: return "ALERTING";
5129 case RIL_CALL_INCOMING: return "INCOMING";
5130 case RIL_CALL_WAITING: return "WAITING";
5131 default: return "<unknown state>";
5132 }
5133}
5134
5135const char *
5136requestToString(int request) {
5137/*
5138 cat libs/telephony/ril_commands.h \
5139 | egrep "^ *{RIL_" \
5140 | sed -re 's/\{RIL_([^,]+),[^,]+,([^}]+).+/case RIL_\1: return "\1";/'
5141
5142
5143 cat libs/telephony/ril_unsol_commands.h \
5144 | egrep "^ *{RIL_" \
5145 | sed -re 's/\{RIL_([^,]+),([^}]+).+/case RIL_\1: return "\1";/'
5146
5147*/
5148 switch(request) {
5149 case RIL_REQUEST_GET_SIM_STATUS: return "GET_SIM_STATUS";
5150 case RIL_REQUEST_ENTER_SIM_PIN: return "ENTER_SIM_PIN";
5151 case RIL_REQUEST_ENTER_SIM_PUK: return "ENTER_SIM_PUK";
5152 case RIL_REQUEST_ENTER_SIM_PIN2: return "ENTER_SIM_PIN2";
5153 case RIL_REQUEST_ENTER_SIM_PUK2: return "ENTER_SIM_PUK2";
5154 case RIL_REQUEST_CHANGE_SIM_PIN: return "CHANGE_SIM_PIN";
5155 case RIL_REQUEST_CHANGE_SIM_PIN2: return "CHANGE_SIM_PIN2";
5156 case RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION: return "ENTER_NETWORK_DEPERSONALIZATION";
5157 case RIL_REQUEST_GET_CURRENT_CALLS: return "GET_CURRENT_CALLS";
5158 case RIL_REQUEST_DIAL: return "DIAL";
5159 case RIL_REQUEST_DIAL_EMERGENCY: return "DIAL";
5160 case RIL_REQUEST_GET_IMSI: return "GET_IMSI";
5161 case RIL_REQUEST_HANGUP: return "HANGUP";
5162 case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: return "HANGUP_WAITING_OR_BACKGROUND";
5163 case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: return "HANGUP_FOREGROUND_RESUME_BACKGROUND";
5164 case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: return "SWITCH_WAITING_OR_HOLDING_AND_ACTIVE";
5165 case RIL_REQUEST_CONFERENCE: return "CONFERENCE";
5166 case RIL_REQUEST_UDUB: return "UDUB";
5167 case RIL_REQUEST_LAST_CALL_FAIL_CAUSE: return "LAST_CALL_FAIL_CAUSE";
5168 case RIL_REQUEST_SIGNAL_STRENGTH: return "SIGNAL_STRENGTH";
5169 case RIL_REQUEST_VOICE_REGISTRATION_STATE: return "VOICE_REGISTRATION_STATE";
5170 case RIL_REQUEST_DATA_REGISTRATION_STATE: return "DATA_REGISTRATION_STATE";
5171 case RIL_REQUEST_OPERATOR: return "OPERATOR";
5172 case RIL_REQUEST_RADIO_POWER: return "RADIO_POWER";
5173 case RIL_REQUEST_DTMF: return "DTMF";
5174 case RIL_REQUEST_SEND_SMS: return "SEND_SMS";
5175 case RIL_REQUEST_SEND_SMS_EXPECT_MORE: return "SEND_SMS_EXPECT_MORE";
5176 case RIL_REQUEST_SETUP_DATA_CALL: return "SETUP_DATA_CALL";
5177 case RIL_REQUEST_SIM_IO: return "SIM_IO";
5178 case RIL_REQUEST_SEND_USSD: return "SEND_USSD";
5179 case RIL_REQUEST_CANCEL_USSD: return "CANCEL_USSD";
5180 case RIL_REQUEST_GET_CLIR: return "GET_CLIR";
5181 case RIL_REQUEST_SET_CLIR: return "SET_CLIR";
5182 case RIL_REQUEST_QUERY_CALL_FORWARD_STATUS: return "QUERY_CALL_FORWARD_STATUS";
5183 case RIL_REQUEST_SET_CALL_FORWARD: return "SET_CALL_FORWARD";
5184 case RIL_REQUEST_QUERY_CALL_WAITING: return "QUERY_CALL_WAITING";
5185 case RIL_REQUEST_SET_CALL_WAITING: return "SET_CALL_WAITING";
5186 case RIL_REQUEST_SMS_ACKNOWLEDGE: return "SMS_ACKNOWLEDGE";
5187 case RIL_REQUEST_GET_IMEI: return "GET_IMEI";
5188 case RIL_REQUEST_GET_IMEISV: return "GET_IMEISV";
5189 case RIL_REQUEST_ANSWER: return "ANSWER";
5190 case RIL_REQUEST_DEACTIVATE_DATA_CALL: return "DEACTIVATE_DATA_CALL";
5191 case RIL_REQUEST_QUERY_FACILITY_LOCK: return "QUERY_FACILITY_LOCK";
5192 case RIL_REQUEST_SET_FACILITY_LOCK: return "SET_FACILITY_LOCK";
5193 case RIL_REQUEST_CHANGE_BARRING_PASSWORD: return "CHANGE_BARRING_PASSWORD";
5194 case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: return "QUERY_NETWORK_SELECTION_MODE";
5195 case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: return "SET_NETWORK_SELECTION_AUTOMATIC";
5196 case RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL: return "SET_NETWORK_SELECTION_MANUAL";
5197 case RIL_REQUEST_QUERY_AVAILABLE_NETWORKS : return "QUERY_AVAILABLE_NETWORKS ";
5198 case RIL_REQUEST_DTMF_START: return "DTMF_START";
5199 case RIL_REQUEST_DTMF_STOP: return "DTMF_STOP";
5200 case RIL_REQUEST_BASEBAND_VERSION: return "BASEBAND_VERSION";
5201 case RIL_REQUEST_SEPARATE_CONNECTION: return "SEPARATE_CONNECTION";
5202 case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: return "SET_PREFERRED_NETWORK_TYPE";
5203 case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: return "GET_PREFERRED_NETWORK_TYPE";
5204 case RIL_REQUEST_GET_NEIGHBORING_CELL_IDS: return "GET_NEIGHBORING_CELL_IDS";
5205 case RIL_REQUEST_SET_MUTE: return "SET_MUTE";
5206 case RIL_REQUEST_GET_MUTE: return "GET_MUTE";
5207 case RIL_REQUEST_QUERY_CLIP: return "QUERY_CLIP";
5208 case RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE: return "LAST_DATA_CALL_FAIL_CAUSE";
5209 case RIL_REQUEST_DATA_CALL_LIST: return "DATA_CALL_LIST";
5210 case RIL_REQUEST_RESET_RADIO: return "RESET_RADIO";
5211 case RIL_REQUEST_OEM_HOOK_RAW: return "OEM_HOOK_RAW";
5212 case RIL_REQUEST_OEM_HOOK_STRINGS: return "OEM_HOOK_STRINGS";
5213 case RIL_REQUEST_SET_BAND_MODE: return "SET_BAND_MODE";
5214 case RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE: return "QUERY_AVAILABLE_BAND_MODE";
5215 case RIL_REQUEST_STK_GET_PROFILE: return "STK_GET_PROFILE";
5216 case RIL_REQUEST_STK_SET_PROFILE: return "STK_SET_PROFILE";
5217 case RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND: return "STK_SEND_ENVELOPE_COMMAND";
5218 case RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE: return "STK_SEND_TERMINAL_RESPONSE";
5219 case RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM: return "STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM";
5220 case RIL_REQUEST_SCREEN_STATE: return "SCREEN_STATE";
5221 case RIL_REQUEST_EXPLICIT_CALL_TRANSFER: return "EXPLICIT_CALL_TRANSFER";
5222 case RIL_REQUEST_SET_LOCATION_UPDATES: return "SET_LOCATION_UPDATES";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005223 case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE:return"CDMA_SET_SUBSCRIPTION_SOURCE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005224 case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE:return"CDMA_SET_ROAMING_PREFERENCE";
5225 case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE:return"CDMA_QUERY_ROAMING_PREFERENCE";
5226 case RIL_REQUEST_SET_TTY_MODE:return"SET_TTY_MODE";
5227 case RIL_REQUEST_QUERY_TTY_MODE:return"QUERY_TTY_MODE";
5228 case RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE";
5229 case RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE:return"CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE";
5230 case RIL_REQUEST_CDMA_FLASH:return"CDMA_FLASH";
5231 case RIL_REQUEST_CDMA_BURST_DTMF:return"CDMA_BURST_DTMF";
5232 case RIL_REQUEST_CDMA_SEND_SMS:return"CDMA_SEND_SMS";
5233 case RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE:return"CDMA_SMS_ACKNOWLEDGE";
5234 case RIL_REQUEST_GSM_GET_BROADCAST_SMS_CONFIG:return"GSM_GET_BROADCAST_SMS_CONFIG";
5235 case RIL_REQUEST_GSM_SET_BROADCAST_SMS_CONFIG:return"GSM_SET_BROADCAST_SMS_CONFIG";
5236 case RIL_REQUEST_CDMA_GET_BROADCAST_SMS_CONFIG:return "CDMA_GET_BROADCAST_SMS_CONFIG";
5237 case RIL_REQUEST_CDMA_SET_BROADCAST_SMS_CONFIG:return "CDMA_SET_BROADCAST_SMS_CONFIG";
5238 case RIL_REQUEST_CDMA_SMS_BROADCAST_ACTIVATION:return "CDMA_SMS_BROADCAST_ACTIVATION";
Ethan Chend6e30652013-08-04 22:49:56 -07005239 case RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY: return"CDMA_VALIDATE_AND_WRITE_AKEY";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005240 case RIL_REQUEST_CDMA_SUBSCRIPTION: return"CDMA_SUBSCRIPTION";
5241 case RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM: return "CDMA_WRITE_SMS_TO_RUIM";
5242 case RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM: return "CDMA_DELETE_SMS_ON_RUIM";
5243 case RIL_REQUEST_DEVICE_IDENTITY: return "DEVICE_IDENTITY";
5244 case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: return "EXIT_EMERGENCY_CALLBACK_MODE";
5245 case RIL_REQUEST_GET_SMSC_ADDRESS: return "GET_SMSC_ADDRESS";
5246 case RIL_REQUEST_SET_SMSC_ADDRESS: return "SET_SMSC_ADDRESS";
5247 case RIL_REQUEST_REPORT_SMS_MEMORY_STATUS: return "REPORT_SMS_MEMORY_STATUS";
5248 case RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING: return "REPORT_STK_SERVICE_IS_RUNNING";
5249 case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: return "CDMA_GET_SUBSCRIPTION_SOURCE";
5250 case RIL_REQUEST_ISIM_AUTHENTICATION: return "ISIM_AUTHENTICATION";
5251 case RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU: return "RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU";
5252 case RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS: return "RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS";
5253 case RIL_REQUEST_VOICE_RADIO_TECH: return "VOICE_RADIO_TECH";
XpLoDWilDba5c6a32013-07-27 21:12:19 +02005254 case RIL_REQUEST_GET_CELL_INFO_LIST: return"GET_CELL_INFO_LIST";
5255 case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: return"SET_UNSOL_CELL_INFO_LIST_RATE";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005256 case RIL_REQUEST_SET_INITIAL_ATTACH_APN: return "RIL_REQUEST_SET_INITIAL_ATTACH_APN";
5257 case RIL_REQUEST_IMS_REGISTRATION_STATE: return "IMS_REGISTRATION_STATE";
5258 case RIL_REQUEST_IMS_SEND_SMS: return "IMS_SEND_SMS";
Howard Sue32dbfd2015-01-07 15:55:57 +08005259 case RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC: return "SIM_TRANSMIT_APDU_BASIC";
5260 case RIL_REQUEST_SIM_OPEN_CHANNEL: return "SIM_OPEN_CHANNEL";
5261 case RIL_REQUEST_SIM_CLOSE_CHANNEL: return "SIM_CLOSE_CHANNEL";
5262 case RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL: return "SIM_TRANSMIT_APDU_CHANNEL";
Howard Subd82ef12015-04-12 10:25:05 +02005263 case RIL_REQUEST_GET_RADIO_CAPABILITY: return "RIL_REQUEST_GET_RADIO_CAPABILITY";
5264 case RIL_REQUEST_SET_RADIO_CAPABILITY: return "RIL_REQUEST_SET_RADIO_CAPABILITY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005265 case RIL_REQUEST_SET_UICC_SUBSCRIPTION: return "SET_UICC_SUBSCRIPTION";
5266 case RIL_REQUEST_ALLOW_DATA: return "ALLOW_DATA";
5267 case RIL_REQUEST_GET_HARDWARE_CONFIG: return "GET_HARDWARE_CONFIG";
5268 case RIL_REQUEST_SIM_AUTHENTICATION: return "SIM_AUTHENTICATION";
5269 case RIL_REQUEST_GET_DC_RT_INFO: return "GET_DC_RT_INFO";
5270 case RIL_REQUEST_SET_DC_RT_INFO_RATE: return "SET_DC_RT_INFO_RATE";
5271 case RIL_REQUEST_SET_DATA_PROFILE: return "SET_DATA_PROFILE";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005272 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED: return "UNSOL_RESPONSE_RADIO_STATE_CHANGED";
5273 case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED: return "UNSOL_RESPONSE_CALL_STATE_CHANGED";
5274 case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: return "UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED";
5275 case RIL_UNSOL_RESPONSE_NEW_SMS: return "UNSOL_RESPONSE_NEW_SMS";
5276 case RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT: return "UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT";
5277 case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: return "UNSOL_RESPONSE_NEW_SMS_ON_SIM";
5278 case RIL_UNSOL_ON_USSD: return "UNSOL_ON_USSD";
5279 case RIL_UNSOL_ON_USSD_REQUEST: return "UNSOL_ON_USSD_REQUEST(obsolete)";
5280 case RIL_UNSOL_NITZ_TIME_RECEIVED: return "UNSOL_NITZ_TIME_RECEIVED";
5281 case RIL_UNSOL_SIGNAL_STRENGTH: return "UNSOL_SIGNAL_STRENGTH";
Howard Subd82ef12015-04-12 10:25:05 +02005282 case RIL_UNSOL_DATA_CALL_LIST_CHANGED: return "UNSOL_DATA_CALL_LIST_CHANGED";
5283 case RIL_UNSOL_SUPP_SVC_NOTIFICATION: return "UNSOL_SUPP_SVC_NOTIFICATION";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005284 case RIL_UNSOL_STK_SESSION_END: return "UNSOL_STK_SESSION_END";
5285 case RIL_UNSOL_STK_PROACTIVE_COMMAND: return "UNSOL_STK_PROACTIVE_COMMAND";
5286 case RIL_UNSOL_STK_EVENT_NOTIFY: return "UNSOL_STK_EVENT_NOTIFY";
5287 case RIL_UNSOL_STK_CALL_SETUP: return "UNSOL_STK_CALL_SETUP";
5288 case RIL_UNSOL_SIM_SMS_STORAGE_FULL: return "UNSOL_SIM_SMS_STORAGE_FUL";
5289 case RIL_UNSOL_SIM_REFRESH: return "UNSOL_SIM_REFRESH";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005290 case RIL_UNSOL_CALL_RING: return "UNSOL_CALL_RING";
5291 case RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED: return "UNSOL_RESPONSE_SIM_STATUS_CHANGED";
5292 case RIL_UNSOL_RESPONSE_CDMA_NEW_SMS: return "UNSOL_NEW_CDMA_SMS";
5293 case RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS: return "UNSOL_NEW_BROADCAST_SMS";
5294 case RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL: return "UNSOL_CDMA_RUIM_SMS_STORAGE_FULL";
5295 case RIL_UNSOL_RESTRICTED_STATE_CHANGED: return "UNSOL_RESTRICTED_STATE_CHANGED";
5296 case RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE: return "UNSOL_ENTER_EMERGENCY_CALLBACK_MODE";
5297 case RIL_UNSOL_CDMA_CALL_WAITING: return "UNSOL_CDMA_CALL_WAITING";
5298 case RIL_UNSOL_CDMA_OTA_PROVISION_STATUS: return "UNSOL_CDMA_OTA_PROVISION_STATUS";
5299 case RIL_UNSOL_CDMA_INFO_REC: return "UNSOL_CDMA_INFO_REC";
5300 case RIL_UNSOL_OEM_HOOK_RAW: return "UNSOL_OEM_HOOK_RAW";
5301 case RIL_UNSOL_RINGBACK_TONE: return "UNSOL_RINGBACK_TONE";
5302 case RIL_UNSOL_RESEND_INCALL_MUTE: return "UNSOL_RESEND_INCALL_MUTE";
5303 case RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED: return "UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED";
5304 case RIL_UNSOL_CDMA_PRL_CHANGED: return "UNSOL_CDMA_PRL_CHANGED";
5305 case RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE: return "UNSOL_EXIT_EMERGENCY_CALLBACK_MODE";
5306 case RIL_UNSOL_RIL_CONNECTED: return "UNSOL_RIL_CONNECTED";
5307 case RIL_UNSOL_VOICE_RADIO_TECH_CHANGED: return "UNSOL_VOICE_RADIO_TECH_CHANGED";
Ethan Chend6e30652013-08-04 22:49:56 -07005308 case RIL_UNSOL_CELL_INFO_LIST: return "UNSOL_CELL_INFO_LIST";
Andrew Jiangca4a9a02014-01-18 18:04:08 -05005309 case RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED: return "RESPONSE_IMS_NETWORK_STATE_CHANGED";
Howard Sue32dbfd2015-01-07 15:55:57 +08005310 case RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED: return "UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED";
5311 case RIL_UNSOL_SRVCC_STATE_NOTIFY: return "UNSOL_SRVCC_STATE_NOTIFY";
5312 case RIL_UNSOL_HARDWARE_CONFIG_CHANGED: return "HARDWARE_CONFIG_CHANGED";
5313 case RIL_UNSOL_DC_RT_INFO_CHANGED: return "UNSOL_DC_RT_INFO_CHANGED";
Howard Subd82ef12015-04-12 10:25:05 +02005314 case RIL_UNSOL_RADIO_CAPABILITY: return "UNSOL_RADIO_CAPABILITY";
5315 case RIL_UNSOL_ON_SS: return "UNSOL_ON_SS";
5316 case RIL_UNSOL_STK_CC_ALPHA_NOTIFY: return "UNSOL_STK_CC_ALPHA_NOTIFY";
Howard Sue32dbfd2015-01-07 15:55:57 +08005317 case RIL_REQUEST_SHUTDOWN: return "SHUTDOWN";
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005318 default: return "<unknown request>";
5319 }
5320}
5321
Howard Sue32dbfd2015-01-07 15:55:57 +08005322const char *
5323rilSocketIdToString(RIL_SOCKET_ID socket_id)
5324{
5325 switch(socket_id) {
5326 case RIL_SOCKET_1:
5327 return "RIL_SOCKET_1";
5328#if (SIM_COUNT >= 2)
5329 case RIL_SOCKET_2:
5330 return "RIL_SOCKET_2";
5331#endif
5332#if (SIM_COUNT >= 3)
5333 case RIL_SOCKET_3:
5334 return "RIL_SOCKET_3";
5335#endif
5336#if (SIM_COUNT >= 4)
5337 case RIL_SOCKET_4:
5338 return "RIL_SOCKET_4";
5339#endif
5340 default:
5341 return "not a valid RIL";
5342 }
5343}
5344
Daniel Hillenbrand601dc852013-07-07 10:06:59 +02005345} /* namespace android */
Dheeraj Shettycc231012014-07-02 21:27:57 +02005346
5347void rilEventAddWakeup_helper(struct ril_event *ev) {
5348 android::rilEventAddWakeup(ev);
5349}
5350
5351void listenCallback_helper(int fd, short flags, void *param) {
5352 android::listenCallback(fd, flags, param);
5353}
5354
5355int blockingWrite_helper(int fd, void *buffer, size_t len) {
5356 return android::blockingWrite(fd, buffer, len);
5357}